Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # program to find gcd of 2 numbers
- # method to find gcd of 2 numbers
- # keep subtracting smaller number from larger until they both are equal
- def gcd(num1,num2):
- if num1 > num2:
- while num2 != 0:
- # calculate the quotient
- quotient = int(num1 / num2)
- # store the num2 in temp
- temp = num2
- num2=num1-x*num2
- num1=temp
- return num1
- else:
- while num1 != 0:
- # calculate the quotient
- quotient = int(num2/num1)
- # store the num1 in temp
- temp=num1
- num1=num2-x*num1
- num2=temp
- return num2
- # main function
- cont = True
- while cont:
- number1 = int(input("Enter the first number : "))
- number2 = int(input("Enter the second number : "))
- answer = gcd(number1, number2)
- print("The GCD of " + str(number1) + " and " + str(number2) + " is " + str(answer))
- n = int(input("Do you want to continue (1/0): "))
- if n == 0:
- cont = False
- print()
Add Comment
Please, Sign In to add comment