Recursive Functions

Recursive functions: what are they?

Recursive functions, often known as recursion, refer to the action of a function calling a copy of itself to address minor issues.When a function calls itself directly or indirectly, it is said to be recursing. Recursive functions are those that call themselves or their corresponding counterparts.Recursive functions are any functions that call themselves repeatedly.By breaking down a big problem into simpler or easier ones, this makes programming easier.Such functions are subjected to a termination condition to prevent them from running duplicate instances of themselves indefinitely. The base condition is another name for this.

What is a base condition?

The basic case is the scenario in which the function doesn’t recur.The base case, for instance, is when we attempt to use recursion to get the factorial of a number and our number ends up being less than 1.

Recursive Case

The term “recursive case” refers to situations when a function repeatedly invokes itself to carry out a subtask, which is typically the same problem broken down into numerous smaller sections.

#include <stdio.h>
int factorial(int num)
{
    if (num > 0)
    {
        return num * factorial(num - 1);
    }
    else
    {
        return 0;
    }
} 
int main()
{
    int ans = factorial(10);
    printf("%d", ans);
    return 0;
}

Output: 3628800

Shubhajna Rai
Shubhajna Rai

A Civil Engineering Graduate interested to share valuable information with the aspirants.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.

    StudentProjects.in