C Program to Find LCM of Two Numbers using Recursion
Write a Program to Find LCM of Two Numbers using Recursion
// C Program to Find LCM of Two Numbers using Recursion #include <stdio.h> void LCM(int n1, int n2) { int max_div = (n1 > n2) ? n1 : n2; int flag = 1; while(flag) { if(max_div % n1 == 0 && max_div % n2 == 0) { printf("\nLCM %d and %d = %d", n1, n2, max_div); break; } else { ++max_div; } } } int main() { int n1,n2; printf("Enter Number 1 :--> "); scanf("%d", &n1); printf("Enter Number 2 :--> "); scanf("%d", &n2); LCM(n1, n2); return 0; }
Output:
Enter Number 1 :--> 45
Enter Number 2 :--> 25
LCM 45 and 25 = 225