C Program to Calculate LCM of Two Numbers using For Loop
Write a Program to Calculate LCM of Two Numbers using For Loop
// C Program to Calculate LCM of Two Numbers using For Loop /* LCM is the smallest number which is divided by both */ #include <stdio.h> int main() { int n1, n2, m, n; printf("Enter number 1 :--> "); scanf("%d", &n1); printf("Enter number 2 :--> "); scanf("%d", &n2); m = n1; n = n2; int number1 = n1, number2 = n2; for(; n1 != n2; ) { if(n1 > n2) { n1 = n1 - n2; } else { n2 = n2 - n1; } } int gcd = n1; printf("LCM of %d and %d is : %d ",m, n, (number1 * number2) / gcd); return 0; }
Output:
Enter number 1 :--> 25
Enter number 2 :--> 12
LCM of 25 and 12 is : 300