Posts

Showing posts with the label LCM in python

Python program to find LCM of two numbers

Image
Python program to find LCM of two numbers LCM stands for Least Common Multiple.  LCM of two numbers is the smallest number that can be divisible by both numbers.  For example, Consider 10 and 12, Factors of 10 => 2, 5 Factors of 12 => 2, 2, 3 LCM of 10, 12 => 2 x 2 x 3 x 5 = 60 Procedure : 1. Start. 2. Get the two numbers as input from the user. 3. Define a function for calculating lcm. 4. Find the greatest of two numbers. 5. loop(true)      if (max_elt%n1 = 0) and (max_elt%n2 = 0)                    => lcm = max_elt                    => break the loop     increment max_elt 6. Return lcm 7. Call the function to calculate the lcm by passing the two numbers as arguments. 8. print the lcm. 9. End.           Code : #function for lcm of two numners def calc_lcm(num_1, num_2): #find the greatest element if (num_1 > num_2): max_elt = num_1 else : max_elt = num_2 while(True): #number that is divisible by both the numbers if((max_elt%num_1==0)and (max_elt%