/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include /* * gcd.c -- calculate the greatest common divisor of two integers */ // function declaration int gcd(int, int); int main ( int argc, char *argv[] ) { int a; int b; if ( argc != 3 ) { fprintf(stderr, "Usage: %s number1 number2\n", argv[0]); exit(-1); } else { a = atoi(argv[1]); b = atoi(argv[2]); } printf("gcd(%d, %d): %d\n", a, b, gcd(a, b)); return 0; } // function definition int gcd ( int a, int b ) { if ( b == 0 ) { return a; } else { return gcd(b, a%b); } }