- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a, b, c,sum=0,smaller;
- cout<<"輸入第一個數: ";
- cin>>a;
- cout<<"輸入第二個數: ";
- cin>>b;
- cout<<"輸入第三個數: ";
- cin>>c;
- smaller=(a<b)?a:b;
- smaller=(a<c)?a:c;
- smaller=(c<b)?c:b;
- cout<<a<<"與"<<b<<"與"<<c<<"的公因數有: ";
- for(int i=1; i<=smaller; i++)
- {
- if (a%i==0 && b%i==0 && c%i==0)
- {
- cout<<i<<" ";
- sum++;
- }
- }
- cout<<endl;
- cout<<"總共有"<<sum<<"個因數"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |