Return (num1 / calculateGCD(num1, num2)) * num2 Recursive function to find LCM of 2 numbers Related: How to Add and Subtract Two Matrices in C , Python, and JavaScript C Program to Find the LCM of Two Numbersīelow is the C program to find the LCM of two numbers: // C program to find LCM of 2 numbers To find the LCM of two numbers programmatically, you need to use the function to find the GCD of two numbers. You can find the LCM of two numbers using the following mathematical formula: num1 * num2 = LCM(num1, num2) * GCD(num1, num2) The least common multiple (LCM) of two numbers is the smallest positive integer that is perfectly divisible by the two given numbers. GCD of 75 and 50 is 25 JavaScript Program to Find the GCD of Two Numbersīelow is the JavaScript program to find the GCD of two numbers: // JavaScript program to find GCD/HCF of 2 numbersĭocument.write( "GCD of " num1 " and " num2 " is " calculateGCD(num1, num2) "ĭocument.write( "GCD of " num3 " and " num4 " is " calculateGCD(num3, num4) "ĭocument.write( "GCD of " num5 " and " num6 " is " calculateGCD(num5, num6) "ĭocument.write( "GCD of " num7 " and " num8 " is " calculateGCD(num7, num8) "ĭocument.write( "GCD of " num9 " and " num10 " is " calculateGCD(num9, num10) " Printf( "GCD of %d and %d is %d \n", num9, num10, calculateGCD(num9, num10)) Printf( "GCD of %d and %d is %d \n", num7, num8, calculateGCD(num7, num8)) Printf( "GCD of %d and %d is %d \n", num5, num6, calculateGCD(num5, num6)) Printf( "GCD of %d and %d is %d \n", num3, num4, calculateGCD(num3, num4)) Printf( "GCD of %d and %d is %d \n", num1, num2, calculateGCD(num1, num2)) Recursive function to find GCD/HCF of 2 numbers Now, the remainder becomes 0, thus the GCD of 75 and 50 is 25.Ĭ Program to Find the GCD of Two Numbersīelow is the C program to find the GCD of two numbers: // C program to find GCD/HCF of 2 numbers.Divide the smaller number by the remainder of the previous operation.Divide the greater number by the smaller number and take the remainder.This process is repeated until the remainder is 0.įor example, if you want to find the GCD of 75 and 50, you need to follow these steps: In the Euclidean algorithm, the greater number is divided by the smaller number, then the smaller number is divided by the remainder of the previous operation. You can find the GCD of two numbers using the Euclidean algorithm. The greatest common divisor (GCD) or highest common factor (HCF) of two numbers is the largest positive integer that perfectly divides the two given numbers.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |