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