From 46f63b0a96f168ccb7a4e44bb22f9b57d05945f1 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Mon, 29 Aug 2022 13:09:29 +0530 Subject: [PATCH 01/11] Added Files & ignored some --- factorial.cpp | 14 ++++++++++++++ functions.h | 2 ++ hello.cpp | 6 ++++++ main.cpp | 9 +++++++++ 4 files changed, 31 insertions(+) create mode 100644 factorial.cpp create mode 100644 functions.h create mode 100644 hello.cpp create mode 100644 main.cpp diff --git a/factorial.cpp b/factorial.cpp new file mode 100644 index 0000000..644ae4a --- /dev/null +++ b/factorial.cpp @@ -0,0 +1,14 @@ +#include "functions.h" +#include +using namespace std; +int factorial(int n){ + if(n < 0) + { + cout<<"Enter a positive no.\n"; + return -1; + } + else if(n!=1){ + return(n * factorial(n-1)); + } + else return 1; +} diff --git a/functions.h b/functions.h new file mode 100644 index 0000000..cedfc6c --- /dev/null +++ b/functions.h @@ -0,0 +1,2 @@ +void print_hello(); +int factorial(int n); diff --git a/hello.cpp b/hello.cpp new file mode 100644 index 0000000..8e283af --- /dev/null +++ b/hello.cpp @@ -0,0 +1,6 @@ +#include +#include "functions.h" +using namespace std; +void print_hello(){ + cout<<"Hello World!"; +} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c7d89b5 --- /dev/null +++ b/main.cpp @@ -0,0 +1,9 @@ +#include +#include "functions.h" +using namespace std; +int main(){ + print_hello(); + cout<< endl; + cout<<"The factorial of 5 is "<< factorial(5)<< endl; + return 0; +} From b1262c9b5b8f4711a99e1523489ba8c0d430cd85 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Mon, 29 Aug 2022 13:30:37 +0530 Subject: [PATCH 02/11] Changed factorial file --- factorial.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/factorial.cpp b/factorial.cpp index 644ae4a..826bb10 100644 --- a/factorial.cpp +++ b/factorial.cpp @@ -12,3 +12,4 @@ int factorial(int n){ } else return 1; } +// Vishwas Made a change \ No newline at end of file From ceb102be2e13db02e6a94faf30f628d0cfc6a579 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Mon, 5 Sep 2022 11:53:17 +0530 Subject: [PATCH 03/11] Changed cout to printf --- hello.cpp | 2 +- main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hello.cpp b/hello.cpp index 8e283af..a69cc9a 100644 --- a/hello.cpp +++ b/hello.cpp @@ -2,5 +2,5 @@ #include "functions.h" using namespace std; void print_hello(){ - cout<<"Hello World!"; + printf("Hello World!"); } diff --git a/main.cpp b/main.cpp index c7d89b5..a41f4c5 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ using namespace std; int main(){ print_hello(); - cout<< endl; - cout<<"The factorial of 5 is "<< factorial(5)<< endl; + printf("\n"); + printf("The factorial of 5 is %d \n",factorial(5)); return 0; } From 1d510a7693536752e045f9946a166c861b5acfdc Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Mon, 5 Sep 2022 12:00:08 +0530 Subject: [PATCH 04/11] Added negative number check --- factorial.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/factorial.cpp b/factorial.cpp index 826bb10..a8d489e 100644 --- a/factorial.cpp +++ b/factorial.cpp @@ -3,8 +3,8 @@ using namespace std; int factorial(int n){ if(n < 0) - { - cout<<"Enter a positive no.\n"; + { // Added changes for negative numbers + cout<<"Enter a positive no. as an input \n"; return -1; } else if(n!=1){ @@ -12,4 +12,4 @@ int factorial(int n){ } else return 1; } -// Vishwas Made a change \ No newline at end of file +// Vishwas Made a change From 3360ad5b6979d7a303a360fd3cfec258e37bcafc Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Mon, 5 Sep 2022 12:04:44 +0530 Subject: [PATCH 05/11] Reverted printf to cout --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index a41f4c5..c3410f7 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ using namespace std; int main(){ print_hello(); - printf("\n"); - printf("The factorial of 5 is %d \n",factorial(5)); + cout<<"\n"; + cout<<"The factorial of 5 is "< Date: Mon, 5 Sep 2022 12:12:10 +0530 Subject: [PATCH 06/11] Reverted printf to cout --- factorial.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/factorial.cpp b/factorial.cpp index 826bb10..fb6c133 100644 --- a/factorial.cpp +++ b/factorial.cpp @@ -1,10 +1,10 @@ -#include "functions.h" +\#include "functions.h" #include using namespace std; int factorial(int n){ if(n < 0) { - cout<<"Enter a positive no.\n"; + cout<<"Enter a positive no. as an input \n"; return -1; } else if(n!=1){ @@ -12,4 +12,5 @@ int factorial(int n){ } else return 1; } -// Vishwas Made a change \ No newline at end of file +// Added changes for negative number +// Vishwas Made a change From 13cd90c8e8862c05b5325a227e21170385926e45 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Sun, 11 Sep 2022 15:38:00 +0530 Subject: [PATCH 07/11] Added GCD --- functions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/functions.h b/functions.h index cedfc6c..67cb648 100644 --- a/functions.h +++ b/functions.h @@ -1,2 +1,3 @@ void print_hello(); int factorial(int n); +int gcd(int a , int b); From dc5323d746e9d56a2a9d7bc176b49183adbe5834 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Sun, 11 Sep 2022 16:17:28 +0530 Subject: [PATCH 08/11] added non-rec gcd to main --- functions.h | 1 + gcd.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 gcd.cpp diff --git a/functions.h b/functions.h index cedfc6c..89f8d84 100644 --- a/functions.h +++ b/functions.h @@ -1,2 +1,3 @@ void print_hello(); int factorial(int n); +int gcd(int a, int b); diff --git a/gcd.cpp b/gcd.cpp new file mode 100644 index 0000000..0715553 --- /dev/null +++ b/gcd.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +int gcd(int a, int b) +{ + while(a) + { + int tmp = a; + a = b % a; + b = a; + } + return b; +} From 35da23c8bdaa5d74f5d0a008ea76e0317fe32b97 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Sun, 11 Sep 2022 16:19:31 +0530 Subject: [PATCH 09/11] added rec gcd to add-rec-function --- gcd.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gcd.cpp b/gcd.cpp index 0715553..e1789b8 100644 --- a/gcd.cpp +++ b/gcd.cpp @@ -2,11 +2,6 @@ using namespace std; int gcd(int a, int b) { - while(a) - { - int tmp = a; - a = b % a; - b = a; - } - return b; + if(!a) return b; + return gcd(b % a, a); } From fda76dbe2e18b4be67dc39fec589878dc03225d3 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Sun, 11 Sep 2022 16:31:52 +0530 Subject: [PATCH 10/11] Resolved conflict --- functions.h | 2 +- gcd.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 gcd.cpp diff --git a/functions.h b/functions.h index 67cb648..89f8d84 100644 --- a/functions.h +++ b/functions.h @@ -1,3 +1,3 @@ void print_hello(); int factorial(int n); -int gcd(int a , int b); +int gcd(int a, int b); diff --git a/gcd.cpp b/gcd.cpp new file mode 100644 index 0000000..0715553 --- /dev/null +++ b/gcd.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; +int gcd(int a, int b) +{ + while(a) + { + int tmp = a; + a = b % a; + b = a; + } + return b; +} From c03d0520d2f7240a3b170490dda58e022ea80049 Mon Sep 17 00:00:00 2001 From: vermamohit13 Date: Sun, 11 Sep 2022 16:22:39 +0530 Subject: [PATCH 11/11] changes to main --- gcd.cpp | 2 +- main.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gcd.cpp b/gcd.cpp index 0715553..387793b 100644 --- a/gcd.cpp +++ b/gcd.cpp @@ -6,7 +6,7 @@ int gcd(int a, int b) { int tmp = a; a = b % a; - b = a; + b =tmp; } return b; } diff --git a/main.cpp b/main.cpp index c3410f7..4b52130 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,8 @@ using namespace std; int main(){ print_hello(); + int x = 56 , y = 98; + cout<