diff --git a/math/factorial.cpp b/math/factorial.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b13eb52de4e2a8e907c9111d103e2b4e4ee5cf6 --- /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; +}