# Write a C Program to Find LCM of Number using Recursion

By | 29.11.2016

## C Program to Find LCM of Number

Write a C Program to Find LCM of Number using Recursion. Here’s simple Program to Find LCM of Number using Recursion in C Programming Language.

## Recursion : :

• Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
• The C programming language supports recursion, i.e., a function to call itself. But while using recursion, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.
• Recursive functions are very useful to solve many mathematical problems, such as calculating the factorial of a number, generating Fibonacci series, etc.

## Problem : :

The following C program, using recursion, finds the LCM. An LCM is the lowest common multiple of any 2 numbers.

Below is the source code for C Program to Find LCM of Number using Recursion which is successfully compiled and run on Windows System to produce desired output as shown below :

### SOURCE CODE : :

```/* C Program to Find LCM of Number using Recursion */

#include <stdio.h>

int lcm(int, int);

int main()
{
int a, b, result;
int prime[100];

printf("Enter two numbers: ");
scanf("%d%d", &a, &b);
result = lcm(a, b);
printf("The LCM of %d and %d is %d\n", a, b, result);
return 0;
}

int lcm(int a, int b)
{
static int common = 1;

if (common % a == 0 && common % b == 0)
{
return common;
}
common++;
lcm(a, b);
return common;
}```

### Output : :

```***************** OUTPUT ********************

***************** FIRST RUN *****************

Enter two numbers:
14
6
The LCM of 14 and 6 is 42

***************** SECOND RUN *****************

Enter two numbers:
42
96
The LCM of 42 and 96 is 672```

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in the short interval.