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

TOP

返回列表