diff --git a/math/factorial.cpp b/math/factorial.cpp new file mode 100644 index 000000000..8b13eb52d --- /dev/null +++ b/math/factorial.cpp @@ -0,0 +1,17 @@ +// C++ program to find factorial of given number +#include + +// function to find factorial of given number +unsigned int factorial(unsigned int n) { + if (n == 0) + return 1; + return n * factorial(n - 1); +} + +// Driver code +int main() { + int num = 5; + std::cout << "Factorial of " << num << " is " << factorial(num) + << std::endl; + return 0; +}