Skip to content

Commit 34dd706

Browse files
Merge pull request thegauravparmar#23 from ravikontentedge/patch-1
Create Factorial.cpp
2 parents 2a0c74e + a32d086 commit 34dd706

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Factorial.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int n;
6+
long double factorial = 1.0;
7+
8+
cout << "Enter a positive integer: ";
9+
cin >> n;
10+
11+
if (n < 0)
12+
cout << "Error! Factorial of a negative number doesn't exist.";
13+
else {
14+
for(int i = 1; i <= n; ++i) {
15+
factorial *= i;
16+
}
17+
cout << "Factorial of " << n << " = " << factorial;
18+
}
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)