Pls help... does anyone know how to find the least common denominator of 3 numbers in c or c++? Thnx.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Pls help... does anyone know how to find the least common denominator of 3 numbers in c or c++? Thnx..

findLCD

4th Jul 2017, 5:56 PM
Leah Quintin
Leah Quintin - avatar
3 Answers
+ 4
If you already have an equation for the LCD of two numbers, you can just use it like this: int lcd = findLCD(firstNumber, findLCD(secondNumber, thirdNumber));
4th Jul 2017, 7:37 PM
Zeke Williams
Zeke Williams - avatar
+ 1
You can put the return value of another lcm as the 2nd parameter. The easy way: lcm(5, lcm(10, 12)); The also easy way but slightly more work, this works for any number: int numbers[] = {2, 5, 10, 12, 15}; const int numbersSize = std::distance(std::begin(numbers), std::end(numbers)); //#include <numeric> is required for accumulate and where lcm is the lcm function. int r = std::accumulate(numbers, numbers + numbersSize, 1, lcm); std::cout << r << std::endl; If you also need some help with the lcm function let me know. Btw, C++17 has a build in GCD / LCM function ^^
4th Jul 2017, 7:40 PM
Dennis
Dennis - avatar
+ 1
Thank you for the response 😊😊😊 @Dennis @ZekeWilliams
5th Jul 2017, 1:15 AM
Leah Quintin
Leah Quintin - avatar