返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int num =0;

  7.    cout<<"請輸入一個數"<<endl;
  8.    cin>>num;
  9.    
  10.    bool x = true;

  11.    for(int i=2;i<num;i++)
  12.    {
  13.      if(num%i == 0)
  14.       {
  15.        x = false;
  16.        break;
  17.       }
  18.    }
  19.     if(x == true)
  20.     {
  21.      cout<<"是質數"<< endl;   
  22.     }
  23.     else
  24.     {
  25.      cout<<"不是質數"<< endl;
  26.     }   
  27.     system("pause");
  28.     return 0;   
  29. }
複製代碼

TOP

返回列表