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

TOP

返回列表