撰寫一個程式,並列出m~n之間的質數。其中m及n由使用者輸入。 可以用指數的話就用指數~ 謝謝><
不想安靜 畫不完="= 二月 6th, 2010 at 17:33
#include <iostream> using namespace std;
int main(){ int n=0, m=0, i=0, j=0;
cout<<"Please input m: "; cin>>m; cout<<"Please input n: "; cin>>n;
for (i = m; i <= n; i++) { for (j = 2; j < i; j++) if (i % j == 0) break; if (i == j) cout<<" "<<i; } cout<<endl;
return 0; }
不想安靜 畫不完="= 二月 6th, 2010 at 17:33