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