Competitive Programming Questions in Python |
In this article, we are going to write code in Python to compute the highest common divisor between the numbers.
If you are looking for a Python Tutorial Series then it's here
#gcd
def gcd(x,y):
if x>y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
def main():
n1 = int(input('Enter first integer: '))
n2 = int(input('Enter second integer: '))
print('The greatest common divisor or HCF is : ',gcd(n1,n2))
main()
The output of the code is:
Enter first integer: 20
Enter second integer: 30
The greatest common divisor or HCF is : 10
Comments
Post a Comment