Welcome folks today in this blog post we will be
finding gcd or hcf of two numbers using for loop in python. All the full source code of the application is shown below.
In order to get started you need to make an
app.py file and copy paste the following code
# taking first number num1 = int(input("Enter first number: ")) # taking second number num2 = int(input("Enter second number: ")) gcd = 1 # finding GCD for i in range(min(num1,num2),0,-1): if (num1%i) == 0 and (num2%i) == 0: gcd = i break # printing GCD print("The GCD of the two numbers is ", gcd)
Now if you execute the
python script by typing the below command as shown below