Checking the given number is prime or not in C?
#include<stdio.h>
main ()
{
int n,i,c=0;
printf("\n\nEnter number to check :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c=c+1;
}
}
if(c==2)
{
printf("\nNumber is prime.");
}
else
{
printf("\nNumber is not prime.");
}
getch();
}
Comments
Post a Comment