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

  27.        system("pause");
  28.         return 0;
  29. }   
複製代碼

TOP

返回列表