返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     int x, y, z, smaller, sum;
  8.     cout<<"請依序輸入三個正數: ";
  9.     cin>>x>>y>>z;
  10.     smaller=x<y?x:y;
  11.     smaller=y<z?y:z;
  12.     cout<<x<<","<<y<<"與"<<z<<"的公因數有: ";
  13.     for(int i=1; i<=smaller; i++)
  14.     {
  15.         if(x%i==0 && y%i==0)
  16.         {
  17.             cout<<i<<" ";
  18.             sum++;
  19.         }
  20.     }
  21.     cout<<endl;
  22.     cout<<"總共有"<<sum<<"個!"<<endl;
  23.     goto re;
  24.     return 0;
  25. }
複製代碼

TOP

返回列表