Sat Nov 09 2019
LCM
C++ Programming1263 views
File Name: lcm.cpp
/* Lowest Common Multiple */
#include<iostream>
using namespace std;
/* Recursive inline function */
inline int common_divisor(int x, int y) {
/* Conditional operator to return GCD value */
return y == 0 ? x : common_divisor(y, x % y);
}
int main() {
int a, b, gcd, lcm;
cout << "Enter two positive number to find Lowest Common Multiple:" << endl;
/* read two integer from console and store it in "a" and "b" */
cin >> a >> b;
gcd = common_divisor(a, b);
lcm = (a * b) / gcd;
cout << "Lcm of two number is: " << lcm << endl;
return 0;
}
/* Output */
Enter two positive number to find Lowest Common Multiple:
30
20
Lcm of two number is: 60
Reference:
Author:Geekboots