You are here:

C/Recursion

Advertisement


Question
I was going through a "C" program on calculating factorial using recursion,where there was no separate code for calculating factorial i mean in the function it was something like if n>=1 then fact(n)=n*fact(n-1) and in the main the printing was done so just by writing those two statements how can the factorial be calculated?

Answer
Dear janakiram !

Clearly i cant under stand your question
if you want code to compute  factorial just use the code given below!

unsigned int Factorial (unsigned int n)
{
   if (n == 0)
  return 1;
   else
  return n * Factorial (n - 1);
}

You need explanation on this code ?
 This procedure uses a unique feature supported in C/C     language called recursion ie, A function have  the capability call its own image

 For each and every call there are different values passed to the function  , and simultaneously the results will be stored in the stack maintained by the system !

In order to know completely about the stack  , atleast you needs to have some knowledge about the data structure ! if so send in me a personal mail so that i can answer you very clearly about the recursion

if you are a beginner have a little knowledge is enough regarding the recursion.

Regards.
Prince M. Premnath.  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.