- # include <iostream.h>
- const int max =1000;
- const int width =10;
- void main()
- {
- bool s[max+1];
- int i,n,col=0;
- for (i=0;i<=max;i++)
- s[i]=0;
- s[0]=1;
- cout<<max<<"以内的素数有:"<<endl;
- for (n=1;n<=max;n++)
- if (s[n-1]==0)
- {
- cout<<n<<" ";
- if (++col>=width)
- {
- cout<<endl;
- col=0;
- }
- for (i=n;i<=max;i+=n)
- s[i-1]=1;
- }
- if (col!=0)
- cout<<endl;
- }