|
|
@ -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. |
|
|
|
} |
|
|
|
} |
|
|
|
|