返回列表 發帖
[quote][/quote]
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     cout<<"***天才兒童的質數驗證機***"<<endl;
  6.     re:
  7.     int a,sum=0;
  8.     cout<<"請輸入一個正整數:"<<endl;
  9.     cin>>a;
  10.     cout<<endl;
  11.     for(int i=1;i<=a;i++){
  12.         if(a%i==0){
  13.             sum++;


  14.         }
  15.     }
  16.      if(sum==2)
  17.             cout<<a<<"是質數"<<endl;
  18.         else
  19.             cout<<a<<"不是質數"<<endl;
  20. goto re;
  21. system("pause");
  22. return 0;
  23. }
複製代碼

TOP

返回列表