赞
踩
#include <iostream> #include <math.h> using namespace std; void JudgePNumber(int n,int& count) { int j, k; k = (int)sqrt((double)n); for (j = 2; j <= k; j++) { if (n%j == 0)//-----will go out break; } if (j > k) { cout << n << " "; count++; } } int main() { int m,n,j=0; cout<<"please input a number: "<<endl; cin >> m; for (n = 2; n <= m; n++) { JudgePNumber(n,j);//-----引用可以更改 if (j>=10) { cout << endl; j = 0; } } cout << endl; system("pause"); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。