มี Number A, LCM และ GCD ต้องหา Number B อีกตัว ตัวอย่าง A=5, LCM=25, HCF=4 ได้ B=4 ใช้สูตร:
A × B = LCM × HCF
B = (LCM × HCF) / A
ตัวอย่างโค้ด C++
#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);
}
ผลลัพธ์
Another number is: 20