- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int x, y, z, smaller, small, sum;
- cout<<"請輸入第一個數: ";
- cin>>x;
- cout<<"請輸入第二個數: ";
- cin>>y;
- cout<<"請輸入第三個數: ";
- cin>>z;
- smaller=x<y?x:y;
- small=z<small?z:small;
- cout<<x<<"與"<<y<<"與"<<z<<"的最大公因數為: ";
- for(int i=1; i<=smaller; i++)
- {
- if(x%i==0 && y%i==0 && z%i==0)
- {
- cout<<i<<" ";
- sum++;
- }
-
- }
- cout<<endl<<"共有"<<sum<<"個!"<<endl<<endl;
- goto re;
- return 0;
- }
複製代碼 |