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

TOP

返回列表