C / C++ Program to find the HCF / GCD of two numbers using recursion (recursive function)

Leave a Comment
/*  The following program identifies the HCF / GCD (Highest Common Factor / Greatest Common Divider) using the concept of recursion */

#include<stdio.h>
#include<conio.h>
int hcf(int,int);
// function prototyping
int main()
{
int a,b,gcd;
printf("Enter 2 Nos. to calculate HCF: \n");
scanf("%d%d",&a,&b);
gcd=hcf(a,b);
printf("GCD / HCF is : %d",gcd);
getch();
}
int hcf(int x,int y)
//function definition
{
if (y!=0)
return hcf(y,x%y);
else
return x;
}



Screenshot:
C / C++ Program to find the HCF / GCD of two numbers using recursion  (recursive  function) : Highest Common Factor / Greatest Common Divider
C / C++ Program to find the HCF / GCD of two numbers using recursion  (recursive  function)

0 comments: