From c47e99041eedc3faf1e1c3687af30fbd2073d3ba Mon Sep 17 00:00:00 2001 From: divyansh739 <115534606+divyansh739@users.noreply.github.com> Date: Sat, 15 Oct 2022 15:15:47 +0530 Subject: [PATCH] Create divyansh11.cpp --- divyansh11.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 divyansh11.cpp diff --git a/divyansh11.cpp b/divyansh11.cpp new file mode 100644 index 0000000..a4a2203 --- /dev/null +++ b/divyansh11.cpp @@ -0,0 +1,25 @@ +/ Factorial of n = 1*2*3*...*n + +#include +using namespace std; + +int factorial(int); + +int main() { + int n, result; + + cout << "Enter a non-negative number: "; + cin >> n; + + result = factorial(n); + cout << "Factorial of " << n << " = " << result; + return 0; +} + +int factorial(int n) { + if (n > 1) { + return n * factorial(n - 1); + } else { + return 1; + } +}