From 09348c34c462282e78ec7415619ecefaf053d729 Mon Sep 17 00:00:00 2001 From: MangeshShelke007 <77568508+MangeshShelke007@users.noreply.github.com> Date: Sun, 17 Oct 2021 22:07:12 +0530 Subject: [PATCH] a program to find gcd of number --- gcd.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 gcd.cpp diff --git a/gcd.cpp b/gcd.cpp new file mode 100644 index 0000000..af56c9b --- /dev/null +++ b/gcd.cpp @@ -0,0 +1,29 @@ +// C++ program to find GCD of two numbers +#include +using namespace std; +// Recursive function to return gcd of a and b +int gcd(int a, int 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 +int main() +{ + int a = 98, b = 56; + cout<<"GCD of "<