Calculate LCM Of Two Numbers in Python | Python Program For Finding LCM of 2 Numbers

preview_player
Показать описание
How to find LCM of two numbers: Today we will write a Python program to find the LCM of two numbers. This is a Python Program to find the LCM of two numbers with complete explanation. The program takes two numbers and prints the LCM of two numbers.

Best Hindi Videos For Learning Programming:

►C Language Complete Course In Hindi -

►JavaScript Complete Course In Hindi -

►Django Complete Course In Hindi -

Follow Me On Social Media
Рекомендации по теме
Комментарии
Автор

One of the best coding teacher of this era!

sunilpal
Автор

I think we can simplify our code by :-

a = int(input('Enter the First number: '))
b = int(input('Enter the second number: '))
maxNum = max(a, b)

while maxNum % a != 0 or maxNum % b != 0:
maxNum += 1

print(f"The lcm is {maxNum}")

aditgaur
Автор

LCM to n numbers

# LCM of n numbers
n = int(input("Enter value of n : "))
li = []
print("Enter the numbers : ")
for i in range(n):
li.append(int(input()))


def LCM(li):
max = None
for i in range(n):
if max is None or max < li[i]:
max = li[i]
while True:
for i in range(n):
if(max % li[i] == 0):
if( i == n-1):
return max
else:
continue
else:
break

max = max+1


LCM = LCM(li)

print(f"LCM of {li} is {LCM}")


Thanks Harry bhai you teach it so well that now i can easily find the lcm of n numbers

BCS_MohdMaaz-bmvu
Автор

Sir, using this code I've found out both HCF and LCM of two numbers (I've not used math module) :

def hcf(a, b):
if a < b:
c = a + 1
else:
c = b + 1

for i in range(2, c):
if ((a%i == 0) and (b%i == 0)):
= i
return hcf

a = int(input('Enter 1st number : '))
b = int(input('Enter 2nd number : '))
print()
print('The HCF of these two numbers is :', hcf(a, b))

d = (a*b)/hcf(a, b)
print('The LCM of these two numbers is :', int(d))

Hope you like it .

RinkuDevi-muuz
Автор

hi i got this question in an interview i used same method but for large input time limit get exceeded is there any optimal way to solve it

introvertgamer
Автор

a = int(input(" Enter first number\n"))
b = int(input(" Enter second number/n")
maxNum = max( a, b )
while( True ):
If( maxNum%a==0 and maxNum%b==0):
Break
maxNum = maxNum + 1
Print(f"The LCM of {a} and {b} is {maxNum}")

sunilsah
Автор

hello sir i am currently watching your python full playlist and I am on the 36th video of that playlist
and I just wanted to say thank you sir for creating such good videos

ishansrivastava
Автор

sir please make hangman game with python please.

santoshgandhi
Автор

Harry Praji. Bas isika intazaar tha. Wo bhi Apne puri Kar Di. Thanks Praji . Aise hi maths and CP me video. Banayiye. Apka channel best hai. Aur aap to ho hi best. Aur all rounder. Superb explanation.

satyajitdas
Автор

a= int(input(“enter a no”) )
b=int(input (“enter second no”))
i=1
while ((a*i)%b !=0):
i+=1
LCM= a*i;
print(“LCM of”, a “and”, b, “is”, LCM)

focusonmyaim
Автор

i have watched your machine learning playlist and it helped me a lot.
Thank you.

akshayshinde
Автор

Bhaiya aap jaise teacher hona chaiye bas... India sbse aage chla jyega

sanjaytoge
Автор

Harry please make full video with explaining all things on topic “ how to setup python in Microsoft visual studio code” because i am unable to do this and i really want to learn coding with you harry bro

hemrajyadav
Автор

Ethical hacking ka bhi tutorial banao agar appko aata hei.

vihaanshah
Автор

Sir codeing karne ke liye best 💻laptop kaun sa hai

waibhavraj
Автор

Harry bhai kyo na aap programming ke liye maths be sikhane🤩🔥

vigneshnu
Автор

Harry sir plz make a playlist for REACT .Sir u are doing amazing work .

yash
Автор

p=int(input("enter num1:"))
j=int(input("enter num2:"))
if(p>j):
for k in range(1, p+1):
if(p%k==0)and(j%k==0):
l=k
else:
for o in range(1, j+1):
if(p%o==0)and(j%o==0):
l=o
print("LCM of the following numbers is", (int((p*j)/l)))

Simpler.

sachini
Автор

Pura pasand aaya hai nd best incredible teach

vimalkumarchaudhary
Автор

I am working on Android development should I choose flutter or React-Native because these are cross plateform language to develop both iOS and Android apps.

codewithsheri