Computer Science, asked by miraj26, 8 months ago

write a python program to find Lcm&Hcf of a given number using python functions​

Answers

Answered by tumatimahitha152
3

Answer:

LCM:

num1 = int(input())

num2 = int(input())

if(num1 > num2 ):   # Use If condition to find the greatest number among these two.

   max= num1

else:

   max= num2

while(True):

   if(max % num1 == 0 and max % num2 == 0):    

       print(max)

       break;

   max= max+ 1

HCF:

def compute_hcf(x, y):

    if x > y:

       smaller = y

   else:

       smaller = x

   for i in range(1, smaller+1):

       if((x % i == 0) and (y % i == 0)):

           hcf = i  

   return hcf  

num1 = 54  

num2 = 24  

print("The H.C.F. is", compute_hcf(num1, num2))

Run Code

Explanation:

Answered by dhruva17068
0

Answer:

import math

while True:

   try:

       num1 = int(input('Enter The First Number: '))

       break

   except:

       print('Invalid Input)

   try:

       num2 = int(input('Enter The Second Number: '))

       break

   except:

       print('Invalid Input')

hcf = math.gcd()

lcm = num1 * num2 / hcf

print(f'The HCF is {hcf}')

print(f'The LCM is {lcm}')

Explanation:

Importing the math library for computing HCF.

Error Handling

Computing LCM with simple LCM formula.

Printing out HCF and LCM

Please mark as brainliest!!

Similar questions