Sat Nov 09 2019

LCM

C++ Programming1261 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

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.