Moon Light Box

Less is More

C - How to Get the Greatest Common Divisor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<stdlib.h>

int main()
{
    int a, b, temp;

    while(scanf("%d %d", &a, &b) == 2)
    {
        while(a%b)
        {
            temp = a;
            a = b;
            b = temp % b;
        }

        printf("%d\n",b);
    }
    system("PAUSE");
    return 0;
}

Comments