Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create the gcd of two numbers #822

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions the gcd of two numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Recursive function to return gcd of a and b
def gcd(a, b):

# Everything divides 0
if (a == 0):
return b
if (b == 0):
return a

# base case
if (a == b):
return a

# a is greater
if (a > b):
return gcd(a-b, b)
return gcd(a, b-a)

# Driver program to test above function
a = 98
b = 56
if(gcd(a, b)):
print('GCD of', a, 'and', b, 'is', gcd(a, b))
else:
print('not found')