From 5de261fd4461aa2310032e7c527304c9cd2b7e80 Mon Sep 17 00:00:00 2001 From: TannuVashist <85392971+TannuVashist@users.noreply.github.com> Date: Thu, 21 Oct 2021 12:33:05 +0530 Subject: [PATCH] Create find factorial.cpp --- find factorial.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 find factorial.cpp diff --git a/find factorial.cpp b/find factorial.cpp new file mode 100644 index 0000000..60f1e3b --- /dev/null +++ b/find factorial.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int main() { + int n; + long double 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; +}