- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int a,b,g,e=0,f=0,h=0;
- cout<<"請輸入三個整數:";
- cin>>a>>b>>g;
- int c;
- if(a<b){
- c=a;
- }
- else{
- c=b;
- }
- cout<<a<<","<<g<<"和"<<b<<"的公因數有:";
- for(int d=1;d<=c;d++){
- if(a%d==0 and b%d==0 and g%d==0){
- cout<<d<<" ";
- e=e+d;
- f++;
- h=d;
- }
- }
- cout<<"\n公因數加起來的數是:"<<e<<endl;
- cout<<"有"<<f<<"個公因數";
- cout<<"\n最大公因數為"<<h<<endl;
- system("pause");
- return 0;
- }
複製代碼 |