返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5.     re:
  6.     int a,b,s,tmp;
  7.     cout<<"請輸入第一個正整數:"<<endl;
  8.     cin>>a;
  9.     cout<<"請輸入第二個正整數:"<<endl;
  10.     cin>>b;
  11.     cout<<endl;
  12.     cout<<a<<"和"<<b<<"的最大公因數=";
  13.     s=a<b?a:b;
  14.     for(int i=s;i>=1;i--){
  15.         if(a%i==0 && b%i==0){
  16.            tmp=i;
  17.            break;
  18.         }
  19.     }cout<<tmp<<endl;
  20. goto re;
  21. system("pause");
  22. return 0;
  23. }
複製代碼

TOP

返回列表