- #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=(b<c)?b:c;
- smaller=(c<a)?c:a;
- 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;
- }
複製代碼 |