Programming Examples

Write a Python program to find the GCD (Greatest Common Divisor) of two numbers.


Write a Python program to find the GCD (Greatest Common Divisor) of two numbers.

[The largest number that divides both input values without leaving a remainder]

If input is: 60 and 48   then output is: 12

Solution

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

while num1 != num2:
    if num1 > num2:
        num1 = num1 - num2
    else:
        num2 = num2 - num1

print("GCD is:", num1)
▶ RUN

Output/ Explanation:

Latest Current Affairs 2026 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad