+ 1
Pls help... does anyone know how to find the least common denominator of 3 numbers in c or c++? Thnx..
findLCD
3 Respuestas
+ 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));
+ 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 ^^
+ 1
Thank you for the response 😊😊😊 @Dennis @ZekeWilliams