找出1~100的质数
1.使用while循环语句
#include
#include
using namespace std;/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) {int i,j,k,flag;i=2;while (i<=100){flag=1;k=sqrt(i);j=2;while (j<=k)
{if(i%j==0){flag=0;break;}j++;}if (flag)cout<
2.使用do-while循环语句
#include
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) {int i,j,k,flag;i=2;do{flag=1;k=sqrt(i);j=2;do{if(i%j==0){flag=0;break;}j++;}while(j<=k);if (flag)cout<
3.使用for循环语句
#include
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(int argc, char** argv) {int i,j,k,flag;for(i=2;i<=100;i++){flag=1;k=sqrt(i);for(j=2;j<=k;j++){if(i%j==0){flag=0;break;}}if (flag)cout<

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
