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

TOP

返回列表