as

Wednesday, 12 November 2014

Recursions in C


Mechanism in which a function makes a call to itself is called as recursion.

Sample program to demonstrate recursion.

#include <stdio.h>

int getfactorial(int i)
{
   if(i == 1)
   {
      return 1;
   }
   return i * getfactorial(i - 1);
}

void  main()
{
    int i = 4;
    printf("Factorial of %d is %d\n", i, getfactorial(i));
}




No comments:

Post a Comment

Leave your valuable feedback. Your thoughts do matter to us.

Sponsored Links

Popular Posts

Comments

ShareThis