WAP to find LCM and HCF between two numbers

 Q.WAP To find LCM and HCF Between two numbers

Steps to follow:
1.Let use input() function to input first and second number.
2.Now take a for loop to iterate which will go upto first or second number to product of both numbers.
3.Then divide the every value by the first and second number. 
4.if the first and second both are divisible same number then print that number. Because it would be the lcm. 
5.To print LCM use print() function and in print() function you can write any statement inside in string . And that value out of the string. 



"""
WAP to find LCM and HCF of two numbers

Let  understand using example  2 and 3

loop goes upto 2*3=6 from 2
first number will be 2 ,2%2 and 2%3!=0
Second no. 3,3%2!=0 and 3%3==0
third no. 4,4%2==0 and 4%3!=0
Fourth no. 5,5%2!=0 and 5%3!=0
fifth no. 6 ,6%2==0 and 6%3==0
Hence LCM is 6
product of two numbers=HCF*LCM

"""

#First input first and second number using input() function and int()
N1=int(input("Enter a first number :"))   
N2=int(input("Enter a second number:"))


#Use loop and it goes first number to multiplication of two numbers or you can take loop from second number
for i in range(N1,(N1*N2)+1):

    
#Test the condition if any is divisible by first and second numbers



        
    if i%N1==0 and i%N2==0:
        
        print("LCM of the numbers ",N1, "and",N2 ,"is",i)
#If any number is divide borh number then break using break keyword
        break
HCF=N1*N2/i
print("HCF of the numbers ",N1, "and",N2 ,"is",HCF)
            
            
        
WAP to find LCM and HCF between two numbers WAP to find LCM and HCF between two numbers Reviewed by Shubham Prajapati on April 12, 2021 Rating: 5

No comments:

If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat

Powered by Blogger.