Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
Created February 15, 2022 12:06
Show Gist options
  • Select an option

  • Save CodeMaster7000/24b73a949304cbf075dd87a938dc85fd to your computer and use it in GitHub Desktop.

Select an option

Save CodeMaster7000/24b73a949304cbf075dd87a938dc85fd to your computer and use it in GitHub Desktop.
A program in C++ which finds the factorial of any positive integer.
#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