Home » Python Programs » Python Program to Find GCD of Two Numbers Using While Loop

# Python Program to Find GCD of Two Numbers Using While Loop

Simple python program to find gcd of two numbers using while loop. In this program, we can execute the python program to find gcd or lcm of two numbers using a while loop for beginners in a python programming language.

## GCD Definition in Python

The greatest common divisor (GCD) of two or more numbers is the exact divisor number that divides them. It’s also known as the greatest common factor (HCF).

## While Loop Definition in Python

A “While” Loop is used to repeat a block of code an unknown number of times until it meets a condition. The while statement allows you to iterate over a statement until a specified expression is false.

The difference between a for loop and a while loop is that in a for loop, the number of iterations to be performed is already known and is used to obtain a specific result, whereas in a while loop, the command runs until a specific condition is met and the statement is proven false. Using this while loop we can execute the python program to find gcd of two numbers using while loop

## Python Program to Find GCD of Two Numbers Using While Loop

``````a = float(input("Enter the First Value A: "))
b = float(input("Enter the Second Value B: "))
i = 1
while(i <= a and i <= b):
if(a % i == 0 and b % i == 0):
val = i
i = i + 1
print("HCF Value is",val)``````

Enter the First Value A: 45
Enter the Second Value B: 45

HCF Value is 45