Advertisement
paulogp

Factorial

Jul 13th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. // Apple Xcode
  2.  
  3.  
  4. #include <stdio.h>
  5.  
  6. unsigned long the_fact(int the_number)
  7. {
  8.     if (the_number > 1)
  9.     {
  10.         return the_number * the_fact(the_number - 1);
  11.     }
  12.     else
  13.     {
  14.         return 1;
  15.     }
  16. }
  17.  
  18. int main (int argc, const char * argv[])
  19. {
  20.     // factorial
  21.     int the_number = 0;
  22.     int the_result;
  23.  
  24.     printf("Introduza um numero: ");
  25.     scanf("%d", &the_number);
  26.  
  27.     the_result = the_fact(the_number);
  28.     printf("%d! = %d", the_number, the_result);
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement