From bc3c2de23ecf1b90f933895aa624d8a3083b2f83 Mon Sep 17 00:00:00 2001 From: dipu007 <72186394+dipu007@users.noreply.github.com> Date: Fri, 1 Oct 2021 00:45:41 +0530 Subject: [PATCH] Create the gcd of two numbers Python program to find the gcd of two numbers --- the gcd of two numbers | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 the gcd of two numbers diff --git a/the gcd of two numbers b/the gcd of two numbers new file mode 100644 index 0000000..386c679 --- /dev/null +++ b/the gcd of two numbers @@ -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')