アルゴリズム-2つの自然数の最大公約数(C+++)を求めます。

708 ワード

大牛の人工知能教程を共有する。ゼロベース!分かりやすい!ユーモア!あなたも人工知能のチームに加わってほしいです。クリックしてくださいhttp://www.captainbed.net 
/*
 *              - C++ - by Chimomo
 *
 * Answer:     
 */

#include 
#include 
#include 
#include 

using namespace std;

int GreatestCommonDivisor(int a, int b) {
    int t;

    if (a < b) {
        //      ,     a    。
        t = a;
        a = b;
        b = t;
    }

    while (b != 0) {
        //        ,  b 0  。
        t = a % b;
        a = b;
        b = t;
    }

    return a;
}

int main() {
    cout << GreatestCommonDivisor(318, 87632) << endl;
    return 0;
}

// Output:
/*
2

*/