C++ Program to Find LCM of Two Numbers using Recursion
Write C++ Program to Find LCM of Two Numbers using Recursion
// CPP Program to Find LCM of Two Numbers using Recursion #include <iostream> using namespace std; 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) { cout << "\nLCM of " << n1 << " and " << 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