From e1193cc09861aa96278feb40636c95cd0ef200bf Mon Sep 17 00:00:00 2001 From: Vanshika Sisodiya <76210357+vanshika2217@users.noreply.github.com> Date: Sun, 17 Oct 2021 13:49:14 +0530 Subject: [PATCH] Create Gcd.cpp --- Gcd.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Gcd.cpp diff --git a/Gcd.cpp b/Gcd.cpp new file mode 100644 index 0000000..4d03dbe --- /dev/null +++ b/Gcd.cpp @@ -0,0 +1,23 @@ +//to calculate gcd of two given number +#include +using namespace std; +int gcd(int x,int y){ + if(x==y) + return x; + if(x==0) + return y; + if(y==0) + return x; + if(x>y) + return gcd(x-y,y); + if(y>x) + return gcd(x,y-x); + +} +int main() { + int ans,num1,num2; + cin>>num1>>num2; + ans=gcd(num1,num2); + cout<<"the gcd of the given number is: "<