recursion

#include <stdio.h>

void recursiveFunction(int n);

int main() {
    int num = 5;
    recursiveFunction(num);
    return 0;
}

void recursiveFunction(int n) {
    if (n > 0) {
        printf("%d\n", n);
        recursiveFunction(n - 1);
    }
}
  1. The program starts by including the necessary header file (stdio.h), which is required for input and output operations.

  2. The program defines a recursive function named recursiveFunction that takes an integer parameter n. This function will print the value of n and then call itself with n - 1 if n is greater than 0.

  3. The main function is the entry point of the program. It declares an integer variable num and initializes it with the value 5.

  4. The main function then calls the recursiveFunction with the value of num as an argument.

  5. Inside the recursiveFunction, there is a base case check (if (n > 0)) to determine whether the recursion should continue. If n is greater than 0, it prints the value of n and calls itself with n - 1.

  6. The recursive calls continue until the base case is met (i.e., n becomes 0), at which point the recursion stops, and the function returns without making another recursive call.

  7. The output of the program will be: 5 4 3 2 1

This demonstrates how the recursive function counts down from the initial value of num (5 in this case) to 1.