- #include<iostream>
- using namespace std;
- int main()
- {
- int x,y,z,smaller;
- int count=0;
- cout<<"請依序輸入三個正整數:";
- cin>>x>>y>>z;
- if(x<y)
- {
- smaller=x;
- }
- else if(y<x)
- {
- smaller=y;
- }
- if(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<<"\t";
- count++;
- }
- cout<<endl<<"總共有"<<count<<"個!"<<endl;
- }
複製代碼 |