diff --git a/Maths/Factorial/C++/factorial_with_tail_resursion.cpp b/Maths/Factorial/C++/factorial_with_tail_resursion.cpp new file mode 100644 index 00000000..cd965131 --- /dev/null +++ b/Maths/Factorial/C++/factorial_with_tail_resursion.cpp @@ -0,0 +1,15 @@ +#include <iostream> + +long long int factorial_with_tail_recursion(long long int number, long long int accumulator=1 ){ + if(number<=0) + return accumulator; + else + return factorial_with_tail_recursion(number-1, accumulator*number); +} + +int main(){ + std::cout<<factorial_with_tail_recursion(6)<<std::endl; + std::cout<<factorial_with_tail_recursion(7)<<std::endl; + std::cout<<factorial_with_tail_recursion(8)<<std::endl; + return 0; +} \ No newline at end of file