[C language] to create a function to determine whether a positive integer is a prime number, and call this function to find all the prime numbers less than 1000

#include <stdio.h>
int fun(int x)
{
int n;
for(n=2;n<=x-1;n++)
if(x/n==0)
break;
if(n>=x)
return 1;
else
return 0;
}
main()
{
int m;
for(m=2;m<1000;m++)
{
if(fun(m)==1)
printf("%-5d\n",m);
}

}

 

Guess you like

Origin www.cnblogs.com/HGNET/p/11943656.html