- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int n1,n2,n3,i,small,sum;
- int main(void)
- {
- re:
- cout<<"請依序輸入三個正整數: ";
- cin>>n1>>n2>>n3;
- cout<<n1<<","<<n2<<"與"<<n3<<"的公因數有: ";
- small=(n1>n2)?n1:n2;
- small=(n3>n2)?n3:n2;
- for(int i=1;i<=small;i++)
- {
- if(n1%i==0 && n2%i==0 && n3%i==0)
- {
- cout<<i<<' ';
- sum++;
- }
- }
- cout<<"\n總共有"<<sum<<"個!\n";
- system("pause");
- system("cls");
- goto re;
- }
複製代碼 |