/* File: p6test12.c Use Euclid Algorithm for greatest common divisors (gcd) to check that recursive function calls and the return statement works. */ #include int gcd (int a, int b) { int remainder, quotient ; if (a < 0 || b < 0) { printf("Don't use negative numbers!!!\n") ; return -1 ; } if (b == 0 ) { printf ("gcd(%d, %d) = ", a, b) ; return a ; } quotient = a / b ; /* note: integer division */ remainder = a - quotient * b ; printf("gcd(%d, %d) = ", a, b) ; return gcd(b, remainder) ; } main() { int n, m, g ; printf("Enter first number: ") ; scanf("%d", &n) ; printf("Enter second number: ") ; scanf("%d", &m) ; g = gcd(n,m) ; printf ("%d\n", g) ; }