Created
February 15, 2022 12:06
-
-
Save CodeMaster7000/24b73a949304cbf075dd87a938dc85fd to your computer and use it in GitHub Desktop.
A program in C++ which finds the factorial of any positive integer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment