diff --git a/src/calculatorFactorial.c b/src/calculatorFactorial.c index a86dcea..fb1a228 100644 --- a/src/calculatorFactorial.c +++ b/src/calculatorFactorial.c @@ -1,6 +1,13 @@ #include "calculatorFactorial.h" -int calculatorFactorial(int x) +int calculatorFactorial(int num) //implement recursion. The function calls itself so many times, till the breaking condition is fulfilled. { - if (x==0)return 1; - else return x*calculatorFactorial(x-1); + if (num == 0) //breaking condition + { + return 1; + } + else + { + return num * calculatorFactorial(num - 1); //If its not breaking condition, then multiply the number with the same function implemented on the previous number. Eventually it will reach breaking condition. + } } + diff --git a/src/calculatorFactorial.h b/src/calculatorFactorial.h index d6f0383..5dbd323 100644 --- a/src/calculatorFactorial.h +++ b/src/calculatorFactorial.h @@ -3,6 +3,6 @@ #include #include -int calculatorFactorial(int x); +int calculatorFactorial(int num); #endif // CALCULATORFACTORIAL_H