DarthVictor

Exercício p/ forum

Nov 4th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. //Código para retirar dúvida em fórum.
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. int fat(int val)
  6. {
  7. if(val<=0 || val >=16 ){return -1;}
  8. int x=val-1;
  9. int res=val;
  10. while(x > 1)
  11. {
  12. res = res * x;
  13. x--;
  14. }
  15. return res;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.  
  22.     int x=0;
  23.     while(x!=-1)
  24.     {
  25.         scanf("%d",&x);
  26.         printf("%d",fat(x));
  27.     }
  28. return 0;
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment