Python program to find GCD of two numbers

March 22, 2022 · Team EasyExamNotes · 1 min read (est.) · 0 comments

Share on WhatsApp

To write a Python program to find GCD of two numbers. 

# Python Program to find GCD of Two Numbers
a = float(input(” Please Enter the First Value a: “))
b = float(input(” Please Enter the Second Value b: “))
i = 1
while(i <= a and i <= b):
    if(a % i == 0 and b % i == 0):
        gcd = i
    i = i + 1

print(“\n GCD of {0} and {1} = {2}”.format(a, b, gcd))

OUTPUT:
Please Enter the First Value a: 12

Please Enter the Second Value b: 6

GCD of 12.0 and 6.0 = 6

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion