Advertisement
campos20

Untitled

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