-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfact.c
33 lines (32 loc) · 904 Bytes
/
fact.c
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
#include <stdio.h>
int main()
{
int kases;
scanf("%d", &kases);
int kase;
for(kase = 1; kase <= kases; kase++) {
int N;
scanf("%d", &N);
int result[1000];
result[0] = 1;
int length = 1, i, j, temp, carry = 0;
for(i = 2; i <= N; i++) {
for(j = 0; j < length; j++) {
temp = carry + result[j] * i;
carry = temp / 10;
result[j] = temp % 10;
}
while(carry) {
result[j] = carry % 10;
carry /= 10;
j++;
}
length = j;
}
for(int i = length - 1; i >= 0; i--){
printf("%d", result[i]);
}
printf("\n");
}
return 0;
}