C Program to calculate GCD (HCF) through Recursion (Euclid GCD)


 

// Program by Akash Tripathi (@proakash256)
 
// The GCD of two Numbers a and b is same
// as that of b and (a % b) and so on...
 
// This method is known as Euclid GCD. 
 
#include <stdio.h>
int gcd(int a , int b)
{
    if(b == 0)
        return a;
    else
        return gcd(b , a % b);
}
int main()
{
    int a , b;
    printf("Enter two Numbers :\n");
    scanf("%d%d" , &a , &b);
    int g = gcd(a , b);
    printf("The GCD of %d and %d is %d" , a , b , g);
    return 0;
}

Comments