|
#include <math.h>
#include <iostream.h>
#include <iomanip.h>
bool fun(long n);
void main()
{long a=10,b=30,l=0;
if(a%2==0) a++;
for(long m=a;m<=b;m+=2)
if(fun(m))
{if(l++%10==0)
cout <<endl;
cout <<setw(5) <<m;
}
}
bool fun(long n)
{int sqrtm=(int)sqrt(n);
for(int i=2;i<=sqrtm;i++)
if(n%i==0)
return false;
return true;
}
|
答案:11 13 17 19 23 29
[解析]循环体用来判断n是否是质数的函数,在main函数判断10~30之间质数。
|
|