54. C Program To check a Number is Prime number or Not.
How does this program work?
- This Program is used to check the given number is prime number or not.
Here is the code
#include <stdio.h>
int main(void)
{
int n,i,flag=0;
printf("Enter a positive integer\n");
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",n);
else
printf("%d is not a prime number\n",n);
return 0;
}