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

TOP

返回列表