Advertisement
Guest User

fatorial

a guest
Oct 25th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<locale.h>
  4.  
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "Portuguese");
  8.     int fatorial,
  9.         resposta = 1;
  10.  
  11.  
  12.     printf("Cálculo de fatorial\n");
  13.     printf("====================\n");
  14.  
  15.     printf("Digite o valor:\n");
  16.     scanf("%i", &fatorial);
  17.     if(fatorial == 0){
  18.         printf("Sua resposta e : %i\n",resposta);
  19.     } else if(fatorial < 0){
  20.         printf("Nao existe fatorial de numero negativo\n");
  21.         return 0;
  22.     }
  23.     while(fatorial > 1){
  24.         resposta*=fatorial;
  25.         --fatorial;
  26.     }
  27.  
  28.     printf("Sua resposta e : %i\n",resposta);
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement