/*
 * Euclid Algorithm - Greatest Common Divisor - in C - version 1.
 * Author:  Yotam Medini  yotam.medini@gmail.com -- Created: 2007/April/27
 */

#include <stdio.h>   /* for printf */
#include <stdlib.h>  /* for atoi */

int main(int     argc,  /* The number of command line arguments */
         char**  argv   /* The list of command line arguments */ )
{
    int  t;  /* temporary */

    /* Get the numbers from command line */
    int  m = atoi(argv[1]);
    int  n = atoi(argv[2]);

    printf("gcd(%d, %d) = ", m, n);  /* drums ... */

    /* Make sure they are non-negative */
    if (m < 0) { m = -m; }
    if (n < 0) { n = -n; }

    if (m == 0 && n == 0) {
        printf("Infinity\n");  /* Since 0 is divisible by any integer */
    } else {
        /* Now the beautiful Euclid algorithm */
        while (n != 0) {
            t = m % n;  /* Now  0 <= t < n */
            m = n;
            n = t;
        }
        printf("%d\n", m);
    }
    return 0;
} /* main */
