Last active
January 21, 2017 21:38
-
-
Save lnrsoft/7e5eea8f41085bf2a941 to your computer and use it in GitHub Desktop.
Number Factorizer. Enter a number to factorize.
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> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
vector <int> factorial; | |
int result = 1; | |
cout << "Enter a number to factorize: "; | |
cin >> n; | |
if (n == 1 || n < 1) | |
{ | |
cout << n << "! = " << 1 << endl; | |
} | |
if (n > 1) | |
{ | |
for (int i = 0; i < n; i++) | |
{ | |
result *=n-i; | |
factorial.push_back(result); | |
} | |
cout << n << "! = " << factorial[n-2] << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment