C - Recursive Function

<<Previous

Next >>





The functions in C are recursive which means that they can call themselves. The act of self reference is known as recursion. The function contains itself and call itself is called recursive function. Sometimes, the recursive function is also known as tail recursion.

The general form of the recursive function is:

 recursiveFunction(){
   //other statements
   recursiveFunction();
 }

Let's understand the recursive function from the following example program:

#include<stdio.h>


int factorial(int m);
void main()
{
	int n, s;

	printf( "Enter input value:");
	scanf("%d",&n);
	s = factorial(n);
	printf("\nThe result is: %d",s);
	getch();
}

int factorial(int n)
{
	int result;
	if(n < 0)
	  return -1;
	if(n == 0)
	  return 1;
	result = n * factorial(n - 1);
	return(result);
}

Output:




<< Previous

Next >>







C - Recursive Function

<<Previous

Next >>





The functions in C are recursive which means that they can call themselves. The act of self reference is known as recursion. The function contains itself and call itself is called recursive function. Sometimes, the recursive function is also known as tail recursion.

The general form of the recursive function is:

 recursiveFunction(){
   //other statements
   recursiveFunction();
 }

Let's understand the recursive function from the following example program:

#include<stdio.h>


int factorial(int m);
void main()
{
	int n, s;

	printf( "Enter input value:");
	scanf("%d",&n);
	s = factorial(n);
	printf("\nThe result is: %d",s);
	getch();
}

int factorial(int n)
{
	int result;
	if(n < 0)
	  return -1;
	if(n == 0)
	  return 1;
	result = n * factorial(n - 1);
	return(result);
}

Output:




<< Previous

Next >>







Learn about Hashing and Hash table

Learn Expression Tree

OS Kernel Architecture

OS Arcitecture of Windows, Linux and MacOS

Learn OS scheduling Algorithms