From 6e81a3502d91931f29b05a170233443c7bb65b35 Mon Sep 17 00:00:00 2001 From: SaheenJasmine <63956055+developweb-Sah@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:20:42 +0530 Subject: [PATCH] Create Multiply.cpp Wrote a program to find GCD using recursion --- hackerrank/cpp/Multiply.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 hackerrank/cpp/Multiply.cpp diff --git a/hackerrank/cpp/Multiply.cpp b/hackerrank/cpp/Multiply.cpp new file mode 100644 index 00000000..f9ff1522 --- /dev/null +++ b/hackerrank/cpp/Multiply.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +int gcd(int a, int b) { + if (a == 0 || b == 0) + return 0; + else if (a == b) + return a; + else if (a > b) + return gcd(a-b, b); + else return gcd(a, b-a); +} +int main() { + int a = 63, b = 42; + cout<<"GCD of "<< a <<" and "<< b <<" is "<< gcd(a, b); + return 0; +}