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));
}




Sponsored Links

Popular Posts

Comments

ShareThis

Google+ Followers

Google+ Badge