To write a program to find the GCD of two numbers using function.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Moodle-Code Runner
- Define a function.
- Get the two numbers from the user.
- Compare the two values, to find the smaller number.
- Use for() and if() loop to find the GCD of the two numbers.
#Program to find the gcd of a number using function
#Developed by:kishore N
#RegisterNumber:212223230106
def gcd():
number1,number2=int(input()),int(input())
if number1<number2:
smaller=number1
else:
smaller=number2
for i in range(1,smaller+1):
if (number1%i==0 and number2%i==0):
gcd1=i
print("GCD of two numbers is:",gcd1)
/*
Program to find the gcd of two number using function.
Developed by:
RegisterNumber:
*/
Thus the program to find the GCD of two numbers is written and verified using python programming.