返回列表 發帖
  1. #include<iostream>
  2. using namespace std;

  3. int main(){
  4.      int x, counter=0;
  5.      cout<<"輸入一正整數: ";
  6.      cin>>x;
  7.      
  8.      for(int i=1; i<=x; i++){
  9.           if(x%i==0){
  10.                counter++;
  11.           }
  12.      }
  13.      
  14.      if(counter==2){
  15.           cout<<x<<"是個質數!"<<endl;
  16.      }
  17.      else
  18.      {
  19.           cout<<x<<"不是質數!"<<endl;
  20.      }
  21.      
  22.      system("pause");
  23.      return 0;   
  24. }
複製代碼

TOP

返回列表