Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Created July 27, 2014 10:34
Show Gist options
  • Save lnrsoft/4b05b400f4f6ff5880d1 to your computer and use it in GitHub Desktop.
Save lnrsoft/4b05b400f4f6ff5880d1 to your computer and use it in GitHub Desktop.
Number Factorizer. Enter a number to factorize. (long double)
// This source code written by Roland Ihasz
#include <iostream>
#include <vector>
#include <iomanip> // std::setprecision
using namespace std;
int main()
{
long double n;
vector <long double> factorial;
long double result = 1;
cout << "Enter a number to factorize: ";
cin >> n;
if (n == 1 || n < 1)
{
cout << n << "! = " << 1 << endl;
}
if (n > 1)
{
for (long double i = 0; i < n; i++)
{
result *=n-i;
factorial.push_back(result);
}
cout << n << "! = " << setprecision(64) << factorial[n-2] << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment