Recursive Function (Recursion) in C

When a function of body calls the same function then it is called as ‘recursive function.’

Example:

Recursion()
{
	printf("Recursion !");
	Recursion();
}

Program :

/* Program to demonstrate function recursion.
Creation Date : 24 Nov 2010 09:45:15 AM
Author : www.technoexam.com [Technowell, Sangli] */

#include <stdio.h>
#include <conio.h>

Recursion()
{
	int no;
	printf("\nRecursion... ");
	printf("\n\n Enter Number : ");
	scanf("%d",&no);
	if (no==3)
		exit(0);
	else
		Recursion();
}

int main(void)
{
	clrscr();
	Recursion();
	return 0;
}

Output :

Recursion...

 Enter Number : 2

Recursion...

 Enter Number : 1

Recursion...

 Enter Number : 3_

Features :
• There should be at least one if statement used to terminate recursion.
• It does not contain any looping statements.

Advantages :
• It is easy to use.
• It represents compact programming strctures.

Disadvantages :
• It is slower than that of looping statements because each time function is called.

Note :
• It can be applied to calculate factorial of a number, fibonancci series.

Leave A Comment

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