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

TOP

返回列表