本帖最後由 尤泓鈞 於 2011-12-3 10:32 編輯
- #include<iostream>
- using namespace std;
- int main()
- {
- int a,b,c,d,e=0,min;
- cout<<"請輸入第一個數字:";
- cin>>a;
- cout<<"請輸入第二個數字:";
- cin>>b;
- cout<<"請輸入第三個數字:";
- cin>>c;
- min=(c<d)?c:d;
- d=(a<b)?a:b;
- cout<<a<<"和"<<b<<"跟"<<c<<"的公因數有: ";
- for(int i=1; i<=min; i++)
- {
- if(a%i==0 && b%i==0 &&b%i==0)
- {
- cout<<i<<" "<<endl;
- e++;
- }
- }
- cout<<"總共有"<<e<<"個公因數"<<endl;
- cout<<endl;
- system("pause");
- return 0;
- }
複製代碼 |