Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program to find whether a given number is Prime number (number that ca

ID: 3922334 • Letter: W

Question

Write a C program to find whether a given number is Prime number (number that can be divided by 1 and itself).You need to take a number from input and verify whether it's positive or not. If the number is not positive then notify the user and ask to input positive number again. If the number is positive then figure out whether it's prime number or not Write a C program to find the Fibonacci numbers. You have to take a positive number from input and show all the Fibonacci numbers belongs to that range. If the number is not positive then notify the user and ask to input positive number again.

Explanation / Answer

/*program for prime number * /

# include < stdio.h >

# include < conio.h>

void main ( )

{

    int i , n , flag =0 ;

    clrscr();

    printf (" enter the positive integer " ) ;

    scanf("%d", & n);

   for ( i=2 ; i<=n/2 ; i++)

   {

     if ( n%i==0)

       {

          flag =1;

          break;

       }

   }

if ( flag==0)

   printf( "%d is a prime number ", n);

else

printf( " %d is not a prime number " , n);

return 0;

}

o/p

enter the positive integer : 17

17 is a prime number .

/* program for fibonacci number * /

# include < stdio.h>

# include < conio.h >

void main()

{

    int n,a,b,c,d;

    clrscr();

    printf ( " enter the number ");

   scanf ( " %d " , & n) ;

    a=5*n*n+4;

    b=5*n*n-4;

    c= sqrt(a);

    d=sqrt(b);

   if ( ( c*c==a)||( d*d==b))

    printf( " the given no is a fibonacci number ");

else

   printf ( " the given no is not a fibonacci no");

getch();

}

o/p

enter the number 5

the given no is a fibonacci number

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote