#include<iostream.h>

void main()
{
 int ncount=0;
 cout<<"计算1-100之间的素数:/n";
 for(int i=1,k=1;i<=100;i++)
 {
  for(int j=2;j<i;j++)
  {
   if(i%j==0){k=0;break;}
  }
  if(k==1)
  { 
   if(ncount==4)
    {
     cout<<'/n';
     ncount=0;
    }
   cout.width(6);
   cout<<i;
   ncount++;
  }
  k=1;
 }
 cout<<endl;

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐