05-14 02:51
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] Example / 최대공약수(GCM) 알고리즘 본문

Programming/C&C++

[C/C++] Example / 최대공약수(GCM) 알고리즘

cinema4dr12 2014. 6. 12. 11:00

//
//  main.cpp
//
//  Created by gchoi on 2014. 5. 8..
//  Copyright (c) 2014년 gchoi. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <strstream>

using namespace std;

int gcm(int x, int y);
void gcmprint(int x, int y);

int main(int argc, const char * argv[])
{
    gcmprint(10, 5);
    gcmprint(52, 16);
   
    return 0;
}

int gcm(int x, int y) {
    int z;
    while ((z = x % y) != 0) {
        x = y;
        y = z;
    }
   
    return y;
}

void gcmprint(int x, int y) {
    cout << gcm(x, y) << endl;
}

'Programming > C&C++' 카테고리의 다른 글

[C/C++] Example / String Append  (0) 2014.06.12
[C/C++] Example / Vector Class  (0) 2014.06.12
[C/C++] Example / Reading & Writing to a Binary File  (0) 2014.06.12
[C/C++] Example / Reading a File  (0) 2014.06.12
[C/C++] Example / Writing a File  (0) 2014.06.12
Comments