From 6f0f4244bf48c2ffc458fe31d018da0a17e6c99c Mon Sep 17 00:00:00 2001 From: Arthur Spears Date: Sun, 21 Jan 2024 16:12:12 -0800 Subject: added examples --- Exercise5/Exercise5/helpers.h | 2 +- Exercise5/Exercise5/program.cpp | 10 +++++++++- 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)! +} -- cgit v1.2.3