aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Exercise5/Exercise5/helpers.h2
-rw-r--r--Exercise5/Exercise5/program.cpp10
2 files changed, 10 insertions, 2 deletions
diff --git a/Exercise5/Exercise5/helpers.h b/Exercise5/Exercise5/helpers.h
index 6e34ea0..c6a1241 100644
--- a/Exercise5/Exercise5/helpers.h
+++ b/Exercise5/Exercise5/helpers.h
@@ -5,7 +5,7 @@
// Content of the header file
int sum(int a, int b);
-
+long factorial(int a);
diff --git a/Exercise5/Exercise5/program.cpp b/Exercise5/Exercise5/program.cpp
index c48cfd2..1a2f55f 100644
--- a/Exercise5/Exercise5/program.cpp
+++ b/Exercise5/Exercise5/program.cpp
@@ -20,4 +20,12 @@ int sum(int a, int b)
sum = a + b;
return sum;
-} \ No newline at end of file
+}
+
+long factorial(int a)
+{
+ if (a == 0 || a == 1)
+ return 1; //base case returns solid data
+ else
+ return a * factorial(a - 1); //recursive case: a! = a * (a-1)!
+}