14-recursion.c 248 B

1234567891011121314151617
  1. #include <stdio.h>
  2. int factorial(int n) {
  3. if (n <= 1) {
  4. return 1;
  5. } else {
  6. return n * factorial(n - 1);
  7. }
  8. }
  9. int main() {
  10. int num = 5;
  11. int result = factorial(num);
  12. printf("Factorial of %d is %d.\n", num, result);
  13. return 0;
  14. }