c++代码
#include <iostream>
#include<math.h>
#include<iomanip>//setw控制格式
#define N 1000
using namespace std;
int main()
{
int i,j,k,n=0;
for(i=2;i<N;++i)
{
j=(int)sqrt(i);
for(k=2;k<=j;k++)
{
if(i%k==0)
break;
}
if(k>j)
{
n++;//控制每行10个数
cout<<setw(4)<<i;
if(n%10==0)
cout<<endl;
}
}
return 0;
}
运行结果