forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFCTRL2.cpp
43 lines (39 loc) · 1008 Bytes
/
FCTRL2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//code for finding large factorials
#include<iostream>
#include<vector>
int main()
{
using namespace std;
int t;
cin >> t;
for (int T = 0; T < t; T++)
{
int n;
cin >> n; //input of number to find the factorial
vector<int>a;
int count = 0;
a.push_back(1);
for ( int i = 2; i <= n; i++)
{
int temp = 0, m = 0;
while (m <= count) //standard multiplication done through arrays
{
temp += a[m] * i;
a[m] = temp % 10;
temp = temp / 10;
m++;
}
while (temp>0)
{
a.push_back(temp % 10);
temp = temp / 10;
count++;
}
}
for (int j = a.size()-1; j >= 0; j--) //printing the arrays in the reverse order since the most
{ //significant digit is at the end
cout << a[j];
}
cout << endl;
}
}