Recursion

In this article or post we’ve discussing about our Recursion program in function. It is the process of duplicating items in a self-similar function.

What is Recursion?

This is the process of duplicating items in a self-similar way. In programming languages, if a program permits you to call a function inside the same function, then it is described a recursive call of the function. Recursion functions are very beneficial to solve many mathematical problems, such as calculating the factorial of a number, generating Fibonacci series, etc.

The following example calculates the factorial of a given number using a recursive function.
#include <stdio.h>
unsigned long long int factorial(unsigned int i){
    if(i<=1){
        return 1;
     }
     return i*factorial(i-1);
}

int main(){
    int i = 3;
    printf("Factorial of %d\n",i,factorial(i));
    return 0;
}

Output
Factorial of 3 is : 6

How it’s work?

void recursion()
{
......
recursion();
......
}

int main()
{
......
recursion();
......
}
recursion

The C programming language supports recursion, i.e., a function to call itself. But while using this, programmers need to be careful to define an exit condition from the function, otherwise it will go into an infinite loop.

For more know check out our more post and if you need any website or develop your website contact us. Check out our partner’s website

Leave a Comment

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