Created
July 27, 2014 10:34
-
-
Save lnrsoft/4b05b400f4f6ff5880d1 to your computer and use it in GitHub Desktop.
Number Factorizer. Enter a number to factorize. (long double)
This file contains 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
// 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