Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created November 25, 2014 09:15
Show Gist options
  • Save avamsi/a523e88e2ba81228241d to your computer and use it in GitHub Desktop.
Save avamsi/a523e88e2ba81228241d to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int t, fact[200], n, i, j, carry, m, x;
cin >> t;
while (t--)
{
cin >> n;
fact[0] = 1;
m = 1; //number of digits
carry = 0;
for (i = 1; i <= n; i++)
{
for (j = 0; j < m; j++)
{
x = fact[j]*i + carry;
fact[j] = x % 10;
carry = x / 10;
}
while (carry > 0)
{
fact[m] = carry % 10;
carry /= 10;
m++;
}
}
for (i = m - 1; i >= 0; i--)
cout << fact[i];
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment