辗转相除法求最大公约数(c++)

#include <iostream>
using namespace std;

int main()
{
    int m, n, r;
    cin >> m >> n;
    r = m % n;
    while( r )
    {
        m = n;
        n = r;
        r = m % n;
    }
    cout << n << endl;
    return 0;
}
posted @ 2018-11-07 19:01  Sherry_Yue  阅读(4122)  评论(0编辑  收藏  举报