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

TOP

  1. #include <iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    int x;
  7.    int y;
  8.    cout<<"請輸入第一個一正整數:";
  9.    cin>>x;
  10.    cout<<"請輸入第二個一正整數:";
  11.    cin>>y;
  12.    cout<<x<<"與"<<y<<"的最大公因數:";   
  13.    int count = 0;   
  14.    int tmp = x>y ? y : x;
  15.    
  16.    for(int i=tmp;i>=1;i--)
  17.    {
  18.        if(x%i==0 && y%i==0 )
  19.        {
  20.           cout<<i<<" ";
  21.           break;
  22.        }
  23.    }
  24.    cout<<endl;
  25.     system("pause");
  26.     return 0;   
  27. }
複製代碼

TOP

返回列表