输出1000以内素数

#include<iostream>
using namespace std;
int main()
{
 int x=2,k;
 bool t;
 while(x<1000)
 {
  k=2;
  t=true;
  while(k<x)
  {
   if(x%k==0)
   t=false;
   k++;
  }
 if(t)
 cout<<x<<endl;
 x++;
 }
 
}
发布了45 篇原创文章 · 获赞 36 · 访问量 830

猜你喜欢

转载自blog.csdn.net/huangziguang/article/details/104408054