Advertisement
Dido09

Factorial - C

Apr 28th, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //function definition
  4. int factorial(int num) {
  5.  
  6. if (num == 1) /* base case */
  7. return (1);
  8. else
  9. return (num * factorial(num - 1));
  10. }
  11.  
  12. int main() {
  13. int x;
  14. scanf("%d", &x);
  15.  
  16. printf("The factorial of %d is %d\n", x, factorial(x));
  17.  
  18. return 0;
  19. }
  20.  
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement