Lập Trình C/C++ - Lowest Common Multiple

#Code:
#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;
}

0 Comment:

Đăng nhận xét

Thank you for your comments!