forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB0003.cpp
More file actions
52 lines (48 loc) · 767 Bytes
/
B0003.cpp
File metadata and controls
52 lines (48 loc) · 767 Bytes
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
44
45
46
47
48
49
50
51
52
// Problem Code: FCTRL2
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
string fact(int n){
int num, temp, len, i;
vector<int> prod;
string result;
i = 0;
temp = n;
while(temp){
prod.push_back(temp % 10);
temp /= 10;
i++;
}
len = i;
for(int j=2 ; j<n ; j++){
temp = i = 0;
while(i < len){
num = prod[i] * j + temp;
prod[i] = num % 10;
temp = num / 10;
i++;
}
while(temp){
prod.push_back(temp % 10);
temp /= 10;
i++;
}
len = i;
}
reverse(prod.begin(), prod.end());
for(i=0 ; i<prod.size() ; i++)
result += to_string(prod[i]);
return result;
}
int main()
{
int t, n;
cin >> t;
for(int i=1 ; i<=t ; i++){
cin >> n;
cout << fact(n) << endl;
}
return 0;
}