From 670603bbd69e4a5f80331ef74fea68aac1ac35fa Mon Sep 17 00:00:00 2001 From: Mohit Chaudhari <98876305+chomu123@users.noreply.github.com> Date: Mon, 31 Oct 2022 19:32:24 +0530 Subject: [PATCH] Find the Factorial of a Given Number --- Find_the_Factorial_of_a _iven_Number.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Find_the_Factorial_of_a _iven_Number.cpp diff --git a/Find_the_Factorial_of_a _iven_Number.cpp b/Find_the_Factorial_of_a _iven_Number.cpp new file mode 100644 index 0000000..bb040da --- /dev/null +++ b/Find_the_Factorial_of_a _iven_Number.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main() { + int n; + long factorial = 1.0; + + cout << "Enter a positive integer: "; + cin >> n; + + if (n < 0) + cout << "Error! Factorial of a negative number doesn't exist."; + else { + for(int i = 1; i <= n; ++i) { + factorial *= i; + } + cout << "Factorial of " << n << " = " << factorial; + } + + return 0; +} \ No newline at end of file