fork(2) download
  1. #include <stdio.h>
  2.  
  3. int fatorial(int num) {
  4. if (num >= 0) {
  5. int fat = 1;
  6. while (num > 0) {
  7. fat *= num;
  8. num--;
  9. }
  10. return fat;
  11. } else {
  12. return -1;
  13. }
  14. }
  15.  
  16. int main(void) {
  17. printf("%d\n", fatorial(0));
  18. printf("%d\n", fatorial(1));
  19. printf("%d\n", fatorial(5));
  20. printf("%d\n", fatorial(-5));
  21. }
  22.  
  23. //http://pt.stackoverflow.com/q/185600/101
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
1
1
120
-1