在 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP