🔀📚Intermediate
Find LCM of Two Numbers
Find least common multiple
LCM (Least Common Multiple) is the smallest number divisible by both numbers.
Formula: LCM(a,b) = (a × b) / GCD(a,b)
Program Code
lcm.c
C
1#include <stdio.h>23// Function to find GCD4int gcd(int a, int b) {5 while (b != 0) {6 int temp = b;7 b = a % b;8 a = temp;9 }10 return a;11}1213int main() {14 int a, b, lcm;15 16 printf("Enter two numbers: ");17 scanf("%d %d", &a, &b);18 19 // LCM = (a * b) / GCD(a, b)20 lcm = (a * b) / gcd(a, b);21 22 printf("LCM of %d and %d is %d\n", a, b, lcm);23 return 0;24}Output
Enter two numbers: 12 18
LCM of 12 and 18 is 36
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials