返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int x, sum=0;
  9.     cout<<"***天才兒童的質數驗證機***"<<endl<<endl;
  10.     cout<<"請輸入一正整數: ";
  11.     cin>>x;
  12.     for(int i=1; i<=x; i++)
  13.     {
  14.         if(x%i==0)
  15.         {
  16.             sum++;
  17.         }
  18.     }
  19.     if(sum==2)
  20.     cout<<x<<"是個質數!"<<endl;
  21.     else
  22.     cout<<x<<"不是質數!"<<endl;
  23.     system("pause");
  24.     goto re;
  25.     return 0;
  26. }
複製代碼

TOP

返回列表