返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     int x,y,z,s,a=0,b=0,t;
  6.     cout<<"請輸入3個正整數:";
  7.     cin>>x>>y>>z;

  8.     if(y>x){
  9.     s=x;
  10.     }
  11.     else{
  12.     s=y;
  13.     }
  14.     if(s>z)
  15.     {s=z;}
  16.     for(int i=s;i>=1;i--){
  17.     if(x%i==0 && y%i==0 && z%i==0){
  18.     b=i;
  19.     break;
  20.     }}
  21.     cout<<endl<<x<<"和"<<y<<"和"<<z<<"的公因數,最大的是"<<b<<endl;
  22.     system("pause");
  23.     return 0;
  24.     }
複製代碼
Attention Seeker </3

TOP

返回列表