- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main(){
- int x,y,z,s,a=0,b=0,t;
- cout<<"請輸入3個正整數:";
- cin>>x>>y>>z;
- cout<<x<<"和"<<y<<"和"<<z<<"的公因數:"<<endl;
- if(y>x){
- s=x;
- }
- else{
- s=y;
- }
- if(s>z)
- {s=z;}
- for(int i=1;i<=s;i++){
- if(x%i==0 && y%i==0 && z%i==0){
- cout<<i<<" ";
- a=a+1;
- t=i;
- if(t>b){b=t;}
- }}
- cout<<endl<<x<<"和"<<y<<"和"<<z<<"有"<<a<<"個公因數,最大的是"<<b<<endl;
- system("pause");
- return 0;
- }
複製代碼 |