From 8f067f5cef1310b0eb1b8dd6b2f9a0d21f7efd6d Mon Sep 17 00:00:00 2001 From: gargankitbalu <116379663+gargankitbalu@users.noreply.github.com> Date: Sat, 22 Oct 2022 22:30:02 +0530 Subject: [PATCH] Create Ak5.cpp --- Ak5.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Ak5.cpp diff --git a/Ak5.cpp b/Ak5.cpp new file mode 100644 index 0000000..0d9a98f --- /dev/null +++ b/Ak5.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; +}