본문 바로가기

TEST/자료구조와 함께 배우는 알고리즘 입문(C언어)

<5> Q2. 자료구조와 함께 배우는 알고리즘 입문 (C언어)

#include <stdio.h>

int gcd(int x, int y)
{
    int temp;
    while (1)
    {
        if (y == 0)
        {
            return x;
        }
        else
        {
            temp = x;
            x = y;
            y = temp % y;
        }
    }
}

int main(void)
{
    int num1, num2;
    printf("Input two two Number : ");
    scanf("%d %d", &num1, &num2);

    printf("최대공약수는 %d입니다", gcd(num1, num2));
}