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

TOP

返回列表