To Find LCM of Two Numbers in C
- The LCM of two numbers a and b is the smallest positive integer that is perfectly divisible by both a and b (without a remainder). For example: The LCM of 72 and 120 is 360.
Sample Code
#include <stdio.h>
// Recursive function to return gcd of a and b
int gcd(int a, int b)
{
// Everything divides 0
if (a == 0 || b == 0)
return 0;
// Base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
// Function to return LCM of two numbers
int lcm(int a, int b)
{
return (a*b)/gcd(a, b);
}
// Driver program to test above function
int main()
{
int a = 10, b = 28;
printf("LCM of %d and %d is %d ", a, b, lcm(a, b));
return 0;
}
Output
Categorized in:
Tagged in:
Accentur interview questions and answers, algorithm to find lcm of n numbers, algorithm to find lcm of two numbers, algorithm to find lcm of two numbers in c, Applied Materials interview questions and answers, Asian Paints Ltd. interview questions and answers, Bosch India Software interview questions and answers, c program to find hcf of two numbers, c program to find lcm of 2 numbers, c program to find lcm of 3 numbers, c program to find lcm of 3 numbers in c, c program to find lcm of 3 numbers using functions, c program to find lcm of 3 numbers using recursion, c program to find lcm of n numbers, c program to find lcm of two numbers using recursion, Capgemini interview questions and answers, CASTING NETWORKS INDIA PVT LIMITED interview questions and answers, CGI Group Inc interview questions and answers, Chetu interview questions and answers, Ciena Corporation interview questions and answers, Collabera Technologies interview questions and answers, Dell International Services India Pvt Ltd interview questions and answers, DHFL Pramerica Life Insurance Company Ltd interview questions and answers, Elico HealthCare Services Ltd interview questions and answers, find lcm, Flipkart interview questions and answers, flowchart to find lcm of two numbers, flowchart to find lcm of two numbers in c, gcd and lcm in c, hcf and lcm formulas, HCL Technol interview questions and answers, how to do lcm, how to find lcm, how to find lcm of 3 numbers in c++, IBM interview questions and answers, Indecomm Global Services interview questions and answers, lcm examples, lcm finder, lcm formula, lcm method, lcm of 12 and 18, lcm of 3 numbers, lcm of 3 numbers in c using function, lcm of 6 and 8, lcm of fractions, lcm of n numbers formula, lcm of n numbers in python, lcm of two numbers in c++, lcm of two numbers in java, lcm program in clcm meaning, lcm questions, Mavenir interview questions and answers, Mphasis interview questions and answers, NetApp interview questions and answers, Oracle Corporation interview questions and answers, PeopleStrong interview questions and answers, program to find lcm of 3 numbers, program to find lcm of 3 numbers in java, program to find lcm of n numbers in java, R Systems interview questions and answers, Raqmiyat Information Technologies Pvt Ltd interview questions and answers, Reliance Industries Ltd interview questions and answers, SAP Labs India Pvt Ltd interview questions and answers, Tata AIA Life Insurance interview questions and answers, Tech Mahindr interview questions and answers, telibrahma interview questions and answers, The Linde Group interview questions and answers, what is lcm