素数是一个正整数,只能由1和它本身整除。
#include <stdio.h>
#include <math.h>
int main()
{
int flag, isPrime;
long int number = 367, result, i;
if (number == 2) {
printf("/n2 is a prime number/n/n");
return 0;
}
isPrime = 1;
result = ceil(sqrt(number));
for (i = 2; i <= result; i++) {
if ((number % i) == 0) {
isPrime = 0;
break;
}
}
if (isPrime)
printf("/n%ld is a prime number/n/n", number);
else
printf("/n%ld is not a prime number/n/n", number);
return(0);
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266581.html