返回列表 發帖
本帖最後由 蔡沛倢 於 2023-3-17 19:42 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.    int a,b,c=0,d=0,f;
  7.    cout<<"請輸入兩個整數:";
  8.    cin>>a>>b;
  9.    f=a<b?a:b;
  10.    cout<<a<<"和"<<b<<"的最大公因數為:";
  11.    for(int e=f;e>=1;e--){
  12.    if(a%e==0 and b%e==0){
  13.    cout<<e<<endl;
  14.    break;
  15.              }      
  16.            }
  17.    system("pause");
  18.    return 0;   
  19. }
複製代碼

TOP

返回列表