Determine whether a number is prime or not.

#include <stdio.h>

int main(void)
{
int num, n;

printf("\nEnter number : ");
scanf("%d", &num);

/* Try to find a factor of num in the range 2 to (num - 1)
if FOUND, number is not prime,
if NOT FOUND, number is prime */

n = 2;

while(n < num)
{
if( num % n == 0 )
break ; /* num is not prime */

n++; /* Try next number */
}

if(num == n)
printf("%d is prime", num);
else
printf("%d is not prime", num);

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin