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

TOP

返回列表