Advertisement
campos20

Untitled

Jun 2nd, 2020
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // Fatorial de um numero informado
  5. // Autor: Alexandre Campos
  6.  
  7. int le_inteiro(){
  8.     int numero;
  9.  
  10.     printf("Digite um numero:\n");
  11.     scanf("%d", &numero);
  12.  
  13.     return numero;
  14. }
  15.  
  16. int fatorial(int n){
  17.     int resultado = 1;
  18.  
  19.     // Percorre de 1 ate o numero e multiplica o resultado
  20.     for (int i=1; i<=n; i++){
  21.         resultado *= i;
  22.     }
  23.  
  24.     return resultado;
  25. }
  26.  
  27. int main()
  28. {
  29.     // Declaracao
  30.     int n, f;
  31.  
  32.     printf("Exibe o fatorial de um numero\n");
  33.  
  34.     // Entrada de dados
  35.     n = le_inteiro();
  36.  
  37.     // Logica
  38.     f = fatorial(n);
  39.  
  40.     // Saida na tela
  41.     printf("O fatorial de %d e %d\n", n, f);
  42.  
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement