返回列表 發帖
  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.     cout<<x<<"和"<<y<<"和"<<z<<"的公因數:"<<endl;
  9.     if(y>x){
  10.     s=x;
  11.     }
  12.     else{
  13.     s=y;
  14.     }
  15.     if(s>z)
  16.     {s=z;}
  17.     for(int i=1;i<=s;i++){
  18.     if(x%i==0 && y%i==0 && z%i==0){
  19.     cout<<i<<" ";
  20.     a=a+1;
  21.     t=i;
  22.     if(t>b){b=t;}
  23.     }}
  24.     cout<<endl<<x<<"和"<<y<<"和"<<z<<"有"<<a<<"個公因數,最大的是"<<b<<endl;
  25.     system("pause");
  26.     return 0;
  27.     }
複製代碼
Attention Seeker </3

TOP

返回列表