Skip to content

Instantly share code, notes, and snippets.

@lnrsoft
Last active January 21, 2017 21:38
Show Gist options
  • Save lnrsoft/7e5eea8f41085bf2a941 to your computer and use it in GitHub Desktop.
Save lnrsoft/7e5eea8f41085bf2a941 to your computer and use it in GitHub Desktop.
Number Factorizer. Enter a number to factorize.
// 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