Any number is input through the keyboard. Write a program to determine whether the number is a prime or not.

#include<stdio.h>
#include<math.h>

int main()
   {
   int   i, n, isprime;
   printf( "Enter a positive integer number: " );
   scanf( "%d" ,&n);
   if(n<2)
        isprime=0;

   else
       for(i=2;i<sqrt(n);i++)
           {
              isprime=1;

              if(n%i==0)
                 {
                     isprime=0;
                     break;
                 }
        }
    if(isprime==1)
        printf( "\nPRIME NUMBER" );
   
else 
        printf( "\nNOT PRIME NUMBER" );
    return 0;
   }

No comments:

Post a Comment