LCM Program in C | GCD and LCM Program in C
1. LCM Program in C
In this program, the compiler will ask user to enter two positive integers other than zero. When the two numbers are accepted then the program will start doing its operation and finally print the LCM of two numbers.
Output:

2. GCD program in C
Output:

3. Calculate LCM Using GCD
In this program, we have calculated the LCM using the concept of GCD.
Output:

4. LCM Program in C Using Recursion
The Recursion means the user-defined function which calls itself directly or indirectly. In this program, the compiler will ask you to enter two values and the print its LCM Using the recursive function.
Output:

In the above program we have used the traditional LCM formula LCM=(Num1*Num2) / GCD;.
When the Compiler reaches to the line in the main gcd(long x, long y) the compiler will directly move to the function long gcd(long x, long y)
Let’s check above program condition’s if(y==0) will check whether the given number is 0 or not. In recursion, it’s very important to give the condition else that the program will execute infinitely.
Hope you understand the program with logic.
Post a Comment