Prime Number Check
#include <stdio.h>
int isprime(int n)
{
if(n==2 || n==3) return 1;
if(n==1 || n%2==0 || n%3==0) return 0;
for (int i=5;i<=sqrt(n);i=i+6)
{
if(n%i==0 || n%(i+2)==0) return 0;
}
return 1;
}
int main()
{
printf("%d\n",isprime(57));
printf("%d",isprime(61));
return 0;
}
Comments
Post a Comment