大神在哪儿 菜鸟求指教
求100内的素数,代码如下
#include<iostream>
#include<math.h>
#include<iomanip>
const int n;
bool a[n+1];
using namespace std;
int main()
{
for(int i=0;i<=n;i++) a[i]=true;
a[1]=false;
for(int i=2;i<=sqrt(n);++i)
if(a[i])
for(int j=2;j<=n/i;++j)
a[i*j]=false;
for(int i=2,t=0;i<=n;++i)
if(a[i])
{
cout<<setw(5)<<i;
++t;
if(t%5==0) cout<<endl;
}
return 0;
}