Write a C program to find whether a given number is Prime nu

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.

Solution

/*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

 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 w
 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 w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site