在 C++ 中給出 LCM 和 HCF 時查詢另一個數字
假設我們有一個數字 A,以及 LCM 和 GCD 值,我們必須找到另一個數字 B。如果 A = 5,LCM 是 25,HCF 是 4,那麼另一個數字將是 4。我們知道 −
$$𝐴∗𝐵=𝐿𝐶𝑀∗𝐻𝐶𝐹$$
$$𝐵= \frac{LCM*HCF}{A}$$
範例
#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
廣告