From 42acfb5d6af167cd6069919d1b76dff6d2803e03 Mon Sep 17 00:00:00 2001 From: vkodesia21 Date: Sun, 11 Sep 2022 19:59:46 +0530 Subject: [PATCH 1/4] Initial Commit --- functions.h | 1 + gcd.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcd.cpp diff --git a/functions.h b/functions.h index cedfc6c..7e79809 100644 --- a/functions.h +++ b/functions.h @@ -1,2 +1,3 @@ void print_hello(); int factorial(int n); +int gcd(int x,int y); diff --git a/gcd.cpp b/gcd.cpp new file mode 100644 index 0000000..9d583f4 --- /dev/null +++ b/gcd.cpp @@ -0,0 +1,13 @@ +#include "functions.h" + +int gcd(int x,int y){ + int gcd; + for(int i=1; i <= x && i <= y; ++i) + { + // Checks if i is factor of both integers + if(x%i==0 && y%i==0) + gcd = i; + } + return gcd; + +} \ No newline at end of file From 046f66bed46d250d545d322d1c580eb2ccabf305 Mon Sep 17 00:00:00 2001 From: vkodesia21 Date: Sun, 11 Sep 2022 20:03:07 +0530 Subject: [PATCH 2/4] gcd-rec --- functions.h | 1 + gcd.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/functions.h b/functions.h index 7e79809..70e7b22 100644 --- a/functions.h +++ b/functions.h @@ -1,3 +1,4 @@ void print_hello(); int factorial(int n); int gcd(int x,int y); +int gcd_rec(int x, int y); \ No newline at end of file diff --git a/gcd.cpp b/gcd.cpp index 9d583f4..4dd464c 100644 --- a/gcd.cpp +++ b/gcd.cpp @@ -9,5 +9,11 @@ int gcd(int x,int y){ gcd = i; } return gcd; +} +int gcd_rec(int x, int y) { + if (y != 0) + return gcd_rec(y, x % y); + else + return n1; } \ No newline at end of file From 3a16e27a4a8d73f28e9dee047c2be55377b88053 Mon Sep 17 00:00:00 2001 From: vkodesia21 Date: Sun, 11 Sep 2022 20:08:34 +0530 Subject: [PATCH 3/4] print gcd --- main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.cpp b/main.cpp index 71dd884..ac155e5 100644 --- a/main.cpp +++ b/main.cpp @@ -10,5 +10,10 @@ int main(){ if(ans==-1)printf("Invalid input, re-enter by again starting program. Status : %d",ans); else printf("Factorial of %d is %d",n,ans); // cout<<(ans == -1?"Invalid input, re-enter by again starting program":"Factorial of "+to_string(n)+" is "+to_string(ans)); + int x,y; + x=56; + y=98; + int g = gcd(x,y); + cout<<"GCD of "< Date: Sun, 11 Sep 2022 20:11:14 +0530 Subject: [PATCH 4/4] final --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.cpp b/main.cpp index ac155e5..1850fad 100644 --- a/main.cpp +++ b/main.cpp @@ -15,5 +15,7 @@ int main(){ y=98; int g = gcd(x,y); cout<<"GCD of "<