-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2.c
62 lines (44 loc) · 1.26 KB
/
2.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
//Se passar tiro os códigos comentados antigos e os pra dbug depois
int numerosDeDigitosDoFatorial(int num);
void fatorial(int num, int *vetor);
int main(){
int resultado[100000];
int num;
printf("Digite um numero inteiro: ");
scanf("%d",&num);
fatorial(num,resultado);
}//end main
void fatorial(int num, int *vetor){
int i, j,resultado;
int numerosQueContei = 1;
int resto = 0;
vetor[0]=1;
//printf("vetor[0] = ");
//printf("%d\n", vetor[0]);
for(i=1; i<=num; i++){
//printf(" I = %d\n\n",i );
for(j = 0; j < numerosQueContei; j++){
//printf("J = %d\n", j);
//printf("numerosQueContei = %d\n\n", numerosQueContei);
resultado = vetor[j] * i + resto;
//printf("resultado = vetor[j] * i + resto = %d\n", resultado);
vetor[j] = resultado%10;
//printf("vetor[j] = resultado%10 = %d\n", vetor[j]);
resto = resultado / 10;
//printf("resto = vetor[j] / 10 = %d\n", resto );
}
while(resto > 0){
//printf("numerosQueContei = %d\n\n", numerosQueContei);
vetor[numerosQueContei] = resto % 10;
resto = resto / 10;
numerosQueContei++;
}
}
printf("Resultado: ");
for(i = numerosQueContei-1; i >= 0 ; i--){
printf("%d", vetor[i]);
}
}//end fatorial