w1coding.comAll tutorials

C Recursions

C lessons
  1. Environment Setup
  2. Introduction
  3. Variables
  4. Operators
  5. Condition
  6. Loops
  7. Functions
  8. Arrays
  9. Pointers
  10. Strings
  11. Struct
  12. File
  13. Memory
  14. Recursions
  15. Bitwise
  16. Directives
  17. Commandline
  18. Switch
  19. Enum
  20. Structp
  21. Arraysofstr
  22. Macros
  23. Pointer Arrays
  24. Linked
  25. Stack
  26. Queue
  27. Graph

C Recursion

Recursion is a programming technique where a function calls itself to solve a problem. It is commonly used to solve problems like calculating factorials, Fibonacci numbers, etc.

Factorial Example

#include 

int factorial(int n) {
    if (n == 0) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
}

int main() {
    int result = factorial(5);
    printf("Factorial of 5 is: %d\n", result);
    return 0;
}
    

This program calculates the factorial of a number using recursion.