C program to test for a prime number

Below is a C program to test for a prime number –

main(){
       float n, count = 0; i = 3; a;

       printf("\nEnter any number of your choice>>");
       scanf("%f", &n);

       if(n == 0 || n == 1 || n == 2)
           printf("\n%d is not a prime number\n", n);

       while(i > 2 & i < n){
            if(!(n % i))
                count = 1;       
            i++;
       }
       if(count == 0)
          printf("\nPRIME!!");
       else
          printf("\nNot Prime.");
}

Add a Comment

Your email address will not be published. Required fields are marked *