解题思路:一一枚举,再判断是否是质数。
注意事项:注意有用#include<cmath>!!!
参考代码:
#include<iostream> #include<cmath> using namespace std; int main() { int a; cin>>a; for(int i=2;i<a;i++) { int flag=1; for(int j=2;j<=sqrt(i);j++) { if(i%j==0) { flag=0; break; } } if(flag==1) { cout<<i<<" "; } } return 0; }
0.0分
2 人评分
2003年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:632 |
简单的a+b (C语言代码)浏览:548 |
简单的a+b (C语言代码)浏览:573 |
蛇行矩阵 (C语言代码)浏览:753 |
简单的a+b (C语言代码)浏览:546 |
C语言训练-亲密数 (C语言描述,反正怎么都能对)浏览:2169 |
前10名 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:514 |
数列排序 (C语言代码)浏览:617 |
小O的图案 (C语言代码)浏览:915 |