Pages

Saturday, 20 June 2015

Prime Number

Check a given number is prime or not


Coding:

#include
int main()
{
int i,j ,n,flag=0;
printf("Please enter the number:");
scanf("%d",&n);
j=(int)n/2;
for(i=3;i<=j;i++)
{
if(n%i==0)
{
printf("\n The divisor=> %d",i);
flag++;
}
}

if(flag==0)
printf("It is a prime number");
else
printf("It is not a prime number");
return 0;
}

Output:
Please enter the number:29
It is a prime number