- #include<iostream>
- using namespace std;
- int main()
- {
- re:
- cout<<"請依序輸入三個正整數: ";
- int x,y,z,sum=0;
- cin>>x>>y>>z;
- int smaller=x<y?x:y;
- smaller=smaller<z?smaller:z;
- 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;
- goto re;
- }
複製代碼 |