From f65dc470acb9264234be8fab9813ef5a7df4df22 Mon Sep 17 00:00:00 2001 From: Mahesh Reddy P Date: Sun, 31 Oct 2021 14:56:44 +0530 Subject: [PATCH] GCD_of_2_numbers --- Python/GCD_of_two_numbers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python/GCD_of_two_numbers.py diff --git a/Python/GCD_of_two_numbers.py b/Python/GCD_of_two_numbers.py new file mode 100644 index 0000000..5164ce0 --- /dev/null +++ b/Python/GCD_of_two_numbers.py @@ -0,0 +1,22 @@ +# 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) + # b is greater + else: + return GCD(a, b-a) + +print(GCD(24,18)) +# prints 6 in terminal \ No newline at end of file