# Using a while loop to calculate GCD of two numbers

a = int(input("Enter the first number: ")) # Get the first number from user input and convert it to integer
b = int(input("Enter the second number: ")) # Get the second number from user input and convert it to integer

while b != 0: # Loop until b becomes zero
    rem = a % b # Get the remainder of dividing a by b
    a = b # Assign b to a
    b = rem # Assign rem to b

gcd = a # The final value of a is the GCD

print("The GCD of",a,"and",b,"is",gcd) # Print the result

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: