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)
Output

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad