LCM of Two Numbers in C Using Recursion

lcm of two numbers in c using recursion. In this program, we can find the lcm of two numbers using the recursion concept to find the lcm of numbers in the C programming language.

LCM Definition in C

The biggest factor present between two or more numbers is defined by the H.C.F., whereas the least number that is exactly divisible by two or more numbers is defined by the L.C.M. 

The greatest common factor (GCF) is also known as the greatest common factor (HCF), while the least common divisor (LCM) is also known as the least common divisor. 

The LCM value is important in math issues where two things are paired against each other to optimize the quantities of the specified objects.

Recursion Function in C

When a function in C calls a copy of itself, this is referred to as recursion. To put it another way, when a function calls itself, this is referred to as recursion. 

You must define an exit condition on that function when employing recursion; else, it will go into an indefinite loop. 

The process of defining a problem (or a solution to a problem) in terms of (a simpler version of) oneself is referred to as recursion.

LCM of Two Numbers in C Using Recursion

#include<stdio.h>
int recursion_func(int, int); 
int main()
{
int a, b, lcm;
printf("Enter Two Numbers");
scanf("%d%d", &a, &b);
lcm = recursion_func(a,b); 
printf("\n LCM is %d\n",lcm);
return 0;
}
int recursion_func(int a, int b) 
{
static int temp = 1; 
if(temp%a == 0 && temp%b == 0)
{
return temp;
}
else
{
temp++;
recursion_func(a,b);
return temp;
}
}

Output:

Enter Two Numbers
45
67
LCM is 3015