Hi Guy's , Here is the article to display HCF and LCM in python programming. HCF stands for Highest Common Factor and LCM stands for Lowest Common Multiple. About LCM and HCF topics we already in 7th standard . Let's see python programming for LCM and HCF.
Code Explanation :
Here, i have taken two integer variables n1 , n2.
n1 = int (input ('Enter Any Number : ')) : At here " Enter First Number : " that display into output screen.
since here i am using input method so whatever we enter that accept into string and after applying int typecasting that convert
into integer and store value into n1 the same things with n2.
a = n1 that means n1 value go to a.
b = n2 that means n2 value go to b.
while b != 0: if b value not equal to zero then while to continue.
temp = b that means b value go to temp.
b = a%b that means a%b value go to b.
temp = a that means a value go to temp. while loop continue until condition false.
when while loop condition false control out from while loop
hcf = a that means a value go to hcf
lcm = n1 * n2 / hcf , after performing right side arithmatic calculation,the value move to lcm.
print("Highest Common Factor = ",hcf)
that print Highest Common Factor = into output screen with hcf value.
print("Lowest Common Multiple = ",lcm)
that print Lowest Common Multiple = into output screen with lcm value.
Happy Coding...Thanks.
1 comments:
Click here for commentsWhat a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much. find lcm of two numbers in c
ConversionConversion EmoticonEmoticon