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

Introduction

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

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

Leave a Comment