📜  给定LCM和HCF时查找其他数字

📅  最后修改于: 2021-04-29 09:48:05             🧑  作者: Mango

给定数字A以及LCM和HCF,任务是确定另一个数字B。
例子:

Input: A = 10, Lcm = 10, Hcf = 50.
Output: B = 50

Input: A = 5, Lcm = 25, Hcf = 4.
Output: B = 20

公式:-

下面是上述方法的实现:

C++
// CPP program to find other number from given
// HCF and LCM
#include 
using namespace std;
 
// Function that will calculates
// the zeroes at the end
int otherNumber(int A, int Lcm, int Hcf)
{
    return (Lcm * Hcf) / A;
}
 
// Driver code
int main()
{
    int A = 8, Lcm = 8, Hcf = 1;
 
    // Calling function.
    int result = otherNumber(A, Lcm, Hcf);
 
    cout << "B = " << result;
 
    return 0;
}


Java
// Java program to find other number from given
// HCF and LCM
class GFG{
 
// Function that will calculates
// the zeroes at the end
static int otherNumber(int A, int Lcm, int Hcf)
{
    return (Lcm * Hcf) / A;
}
 
// Driver code
public static void main(String args[])
{
    int A = 8, Lcm = 8, Hcf = 1;
 
    // Calling function.
    int result = otherNumber(A, Lcm, Hcf);
 
    System.out.println("B = "+ result);
 
}
}


Python3
# Python 3 program to find other
# number from given HCF and LCM
 
# Function that will calculates
# the zeroes at the end
def otherNumber(a, Lcm, Hcf):
    return (Lcm * Hcf) // A
 
# Driver code
A = 8; Lcm = 8; Hcf = 1
 
# Calling function
result = otherNumber(A, Lcm, Hcf)
print("B =", result)
 
# This code is contributed
# by Shrikant13


C#
// C# program to find other number
// from given HCF and LCM
using System;
 
class GFG
{
 
// Function that will calculates
// the zeroes at the end
static int otherNumber(int A, int Lcm,
                              int Hcf)
{
    return (Lcm * Hcf) / A;
}
 
// Driver code
static public void Main(String []args)
{
    int A = 8, Lcm = 8, Hcf = 1;
 
    // Calling function.
    int result = otherNumber(A, Lcm, Hcf);
 
    Console.WriteLine("B = " + result);
}
}
 
// This code is contributed by Arnab Kundu


PHP


Javascript


输出:
B = 1