Code:
double Factorial(double cur_num)
{
static double rvalue=0.0;
if (cur_num)<=0 return (rvalue);
if (rvalue==0.0)
{
rvalue=1.0;
rvalue*=cur_num;
} else rvalue*=cur_num;
Factorial(cur_num-1.0);
}
I think this should work.
I couldn't think of any way to explain this w/o giving it away.
Here is another example of recursion.
Code:
void QuadExample(int depth,int left,int top,int right,int bottom)
{
if (depth<=0 || ((right-left)<=2)) return;
int midx=(left+right)/2;
int midy=(top+bottom)/2;
//Draw randomly colored square
RGB color(rand()% 255,rand ()%255, rand%255);
DrawSquare(left,top,right,bottom,color);
QuadExample(depth-1,left,midx,top,midy);
QuadExample(depth-1,midx,top,right,midy);
QuadExample(depth-1,left,midy,midx,bottom);
QuadExample(depth-1,midx,midy,right,bottom);
}
This only works if left and top both start at 0. I didn't want to add code to confuse the matter in order to fix this. Also right and bottom are assumed to be larger values than left and top.