最大公約數

/*
Jennifer
2018年2月2日15:51:52-2018年2月2日15:58:00
用歐幾里得方法:只要兩個數不相等,就反覆用大數減小數,直到相等爲止,此相等的數即爲兩數的最大公約數
*/
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        while(a != b)
        {
            if(a>b)
                a=a-b;
            else
                b = b-a;
        }
        cout<<a<<endl;
    }
    return 0;
}

發佈了47 篇原創文章 · 獲贊 29 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章