码迷,mamicode.com
首页 > 其他好文 > 详细

最大公约数

时间:2015-01-05 11:11:57      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:华为入职练习 华为oj

#include<iostream>
using namespace std;

int gcd(int m, int n)
{
    int temp = 0;
    if (m < n)
    {
        temp = m;
        m = n;
        n = temp;
    }
    while (0 != m%n)
    {
        temp = n;
        n = m%n;
        m = n;
    }
    return n;
}

int main()
{
    int m =0, n =0;
    cin>>m>>n;
    cout<<gcd(m, n)<<endl;
    return 0;
}

最大公约数

标签:华为入职练习 华为oj

原文地址:http://blog.csdn.net/xiaohanstu/article/details/42419723

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!