Find the other number when LCM and HCF given in C++

C++Server Side ProgrammingProgramming

Suppose we have a number A, and LCM and GCD values, we have to find another number B. If A = 5, LCM is 25, HCF = 4, then another number will be 4. We know that −

$$𝐴∗𝐡=𝐿𝐢𝑀∗𝐻𝐢𝐹$$

$$𝐡= \frac{LCM*HCF}{A}$$

Example

 Live Demo

#include <iostream>
using namespace std;
int anotherNumber(int A, int LCM, int GCD) {
   return (LCM * GCD) / A;
}
int main() {
   int A = 5, LCM = 25, GCD = 4;
   cout << "Another number is: " << anotherNumber(A, LCM, GCD);
}

Output

Another number is: 20
raja
Published on 21-Oct-2019 11:37:52
Advertisements