Python 3 Script to Find GCD or HCF of two Numbers Using While Loop

Python 3 Script to Find GCD or HCF of two Numbers Using While Loop

Python 3 Script to Find GCD or HCF of two Numbers Using While Loop

# Python program to find GCD of two numbers using the while loop

p, q = None, None

# p & q - denotes the two positive numbers

print ("-----Enter the two positive integer numbers-----")
p = int (input ())
q = int (input ())

while p != q:
    if p > q:
        p -= q
    else:
        q -= p

print ("nThe GCD number is: ", p)
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment