From bc8e8dfc2ba73629cc1bc9ab2a12435a820b6655 Mon Sep 17 00:00:00 2001 From: Akshay Gupta <33252532+Akshay1910@users.noreply.github.com> Date: Fri, 6 Dec 2019 03:32:52 +0530 Subject: [PATCH] factorial.cpp (#561) * Create factorial.cpp * Update and rename Math/factorial.cpp to math/factorial.cpp * Update factorial.cpp * Update factorial.cpp --- math/factorial.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 math/factorial.cpp 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; +}