Write a C program to determine whether an input number is prime or not.

First open CodeBlocks and create a file.Then save the file named test.cpp.Then write the following simple C code.Finally Run the Code.

Code:


#include<stdio.h>

int main()
{
int i,n,p=1;
printf("Enter the number: ");
scanf("%d",&n);

for(i=2; i<n; i++)
{
 if(n%i==0)
  {
   p=0;
   break;
  }
}

if(p!=0)
printf("The number is Prime.");
else
printf("The number is not Prime.");

return 0;
}

Output: