training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

recgcd.c (403B)


      1 /* Exercise 5.42 */
      2 
      3 #include <stdio.h>
      4 
      5 int gcd(int, int);
      6 
      7 int main()
      8 {
      9    int num1, num2;
     10 
     11    printf("Give me two numbers: ");
     12    scanf("%d%d", &num1, &num2);
     13    printf("GCD between %d and %d is %d.\n", num1, num2, gcd(num1, num2));
     14 
     15    return 0;
     16 } /* E0F main */
     17 
     18 /* Calculate the GCD recursively */
     19 int gcd(int x, int y)
     20 {
     21    if(y == 0)
     22       return x;
     23 
     24    return gcd(y, x % y);
     25 } /* eof gcd() */
     26