Python Code: Program to find gcd of two numbers using loops
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # take input from the user num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) # choose the smaller number if num1 > num2: smaller = num2 else: smaller = num1 for i in range(1, smaller+1): if((num1 % i == 0) and (num2 % i == 0)): hcf = i print("The H.C.F. of", num1,"and", num2,"is", hcf) |
Output: