求100至200之间的所有素数。素数即不能被 2——其2次方根√m 中的任一个整数整除。 #include<iostream>#include<cmath>using namespace std;int main(){ int m,k,s; for(m=101;m<200;m+=2) { s=sqrt(m); for(k=2;k<=s;k++) { if(m%k==0) break; } if(m%k!=0) cout<<m<<" "; } return 0;}
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/2588/24005.html
求100至200之间的所有素数。素数即不能被 2——其2次方根√m 中的任一个整数整除。 #include<iostream>#include<cmath>using namespace std;int main(){ int m,k,s; for(m=101;m<200;m+=2) { s=sqrt(m); for(k=2;k<=s;k++) { if(m%k==0) break; } if(m%k!=0) cout<<m<<" "; } return 0;}
阅读(2165) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论