What is recursion in C Language

Today is going to be very special for you all because we are going to look at different and most powerful programming tools. Yes !! I hope you will enjoy it but this is not an easy topic for beginners to understand about it. Don’t worry about it I am here you don’t fear. So Today’s Topic name is – What is recursion in C Language?

What do you mean by Recursion?

Recursion is nothing but it is a process or operation to execute or instruct the set of Instructions repeatedly until a certain condition is met. so in the recursion process, a set of instructions is used to repeat the task, again and again, This set of instructions is called recursive instruction or recursive function and this process is called Recursion.

Use of Recursion in C Language?

In C Language, Many operations are performed using loops, conditional statements, and conditional operators So, these operations can be recursive or not. so let’s go and know about recursive function or non-recursive function.

Recursive function

Recursive function is the special type of function that is used to perform iterative operations and this type of function does call again and again to itself. But the thing to note is that your recursive operation shouldn’t wrong. it may provide infinite results or can be a non-terminated program.

Recursive function Example -
  
  void main()
{ 
         int sum=0; 
        printf("Addition is %d\n .....", addition(sum));
}
     int addition(int temp)
     {
        if(temp<100)
        {
             return addition(temp+1);
          }        
       else
             return temp;
     }
// This is a example of recursive function.

Non-Recursive function

Non-recursive function is also known as simple function or normal function. this type of function is called by another function.

void main()
{
int sum=0;
printf("Addition is %d\n .....", addition(sum)); //called by main function
}
int addition(int temp)
{
return temp;
}

Recursion is used in many major places

Recursion processes are used in many major places to decrease the set of instruction and increase less time execution. Many more examples are based upon recursion. such as Binary searching, Factorial Number, Fibonacci series, e.t.c.

Today we will see one example of recursion – Getting Factorial Calculation using Recursive function.

Factorial in C Language

The C language allows a programmer to write subroutines and functions that call themselves. Such routines are called recursive.

Example of Factorial Function – using recursive method

#include<stdio.h>
 long int factorial(int n);
 int main()
 {
 int n;
 printf("Enter a positive integer: ");
 scanf("%d",&n); 
  printf("Factorial of %d = %ld", n, factorial(n));
 return 0;
 } 
long int factorial(int n)
 { 
if (n>=1)
 return n*factorial(n-1);
 else return 1;
 }

I hope you will understand about Recursion Topic. Above example is the best example for recursion. If you want to above example in pictorial form, you just look it in the below picture. This picture is the pictorial form of your above example and describe line by line instruction with naming. Grab it.

Recursion Factorial Example

Last Lines :

This is a newly growing site to attach computer field or technical students in one place and grab the meaningful content from here. I hope you will join it and enjoy yourself with joining. This is a contact form link. fill-up the form and join us soon.

Do you want to subscribe to our site and get the latest update posts? Click the link – Subscriber form

Web designing courses – with Examples

You can learn – HTML

You can Learn – CSS

Share post

Prajjwal Singh

Tech Blogger || Web developer || Computer Networking Enthusiast || Microsoft SQL Database Management Expert || Software Debugger || Learned DOS OS Structure

This Post Has One Comment

Leave a Reply