Login to ask a question from Recursive program in c

C Program to find GCD of two Numbers using Recursion

Greatest Common Divisor(GCD) of two numbers is a number that divides both of them.

Below is a program to the GCD of the two user input numbers using recursion.

Source code:

#include

// declaring the recursive function

int find_gcd(int , int );

int main()

{

    int a, b, gcd;

    printf("\n\nEnter two numbers to find GCD of \n");

    scanf("%d%d", &a, &b);

    gcd = find_gcd(a, b);

    printf("\n\nGCD of %d and %d is: %d\n\n", a, b, gcd);

    return 0;

}

// defining the function

int find_gcd(int x, int y)

{

    if(x > y)

        find_gcd(x-y, y);

    else if(y > x)

        find_gcd(x, y-x);

    else

    return x;

}

Previous Question Next Question
🔗

Similar Questions

From Recursive program in c · C programming

View All
WhatsApp