Q:

Write C program to find HCF or GCD of two numbers using recursion

0

Write C program to find HCF or GCD of two numbers using recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include <stdio.h>
 
int Findgcd(int x, int y); // Function declaration
 
 
int main()
{
    int num1, num2, hcf;
 
    // Inputting 2 numbers from user
    printf("Enter any 2 numbers to find HCF or GCD: ");
    scanf("%d%d", &num1, &num2);
 
    hcf = Findgcd(num1, num2);
 
    printf("GCD of %d and %d = %d", num1, num2, hcf);
 
    return 0;
}
 
int Findgcd(int x, int y)
{
    if(y == 0)
        return x;
    else
        return Findgcd(y, x%y);
}

Result:

Enter any 2 numbers to find HCF or GCD: 20

50

GCD of 20 and 50 = 10

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write C program to print elements of array using r... >>
<< Write C program to find LCM of two numbers using r...