返回列表 發帖
本帖最後由 張絜晰 於 2023-3-10 20:06 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     int x,y,s=0;
  6.     cout<<"請輸入2個正整數:";
  7.     cin>>x>>y;
  8.     cout<<x<<"和"<<y<<"的公因數:"<<endl;
  9.     if(y>x){
  10.     s=x;}
  11.     else{s=y;}
  12.     for(int i=1;i<=s;i++){
  13.     if(x%i==0 && y%i==0){
  14.     cout<<i<<" ";
  15.     }
  16.     }
  17.     cout<<"\n\n\n\n";
  18.     system("pause");
  19.     return 0;
  20.     }
複製代碼
Attention Seeker </3

TOP

返回列表