HCF program in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# defining a function to calculate HCF def HCF_T4Tutorials(x, y): # selecting the SmallerNumber number if x > y: SmallerNumber = y else: SmallerNumber = x for i
in range(1,SmallerNumber + 1): if((x % i == 0) and (y % i == 0)): hcf = i return hcf # Get input from users Number1 = int(input("Please! Enter the first number: ")) Number2 = int(input("Please! Enter the second number: ")) # Displaying the result for the users print("The H.C.F. of", Number1,"and", Number2,"is", HCF_T4Tutorials(Number1, Number2)) |
Output
Please! Enter the first number: 4
Please! Enter the second number: 5
The H.C.F. of 4 and 5 is 1