/* subject requirements to achieve a simple calculation of nonnegative integer factorial function, and using the function 1! + 2! + 3! +... + n! The value of the
Function interface definition:
Double fact (int n);
Double factsum (int n);
Fact () function should return n factorial, suggest using a recursive implementation, function factsum should return 1. + 2! +... + n! The value of the subject to ensure input and output in the range of the double */
/* the referee sample testing program: */
#include
Double fn (double x, int n);
Int main ()
{
Double x;
int n;
Lf the scanf (" % % d ", & amp; X, & amp; N);
Printf (" % 2 f \ n ", fn (x, n));
return 0;
}
/* out: */
Double fn (double x, int n)
{
Int I, flag=1;
Double x1, sum=0;
for(i=1; i<=n; I++)
{
Int j=I;
If (j==0) return 1;
The else
{
X1=x * fn (x, j - 1);
//judgment in add and classification algorithm operation!
}
The sum +=x1 x flag;
Flag *=1;
}
return sum;
}
Because his understanding of the stack and heap memory, is not very understand the return mechanism of recursive functions and in the process of recursion is not interrupted? And
Is recursive statements below written statements have to wait until after completing a recursive implementation?
CodePudding user response:
I want to know what you said what is interrupted? Recursive calls as well as ordinary functions, returning mechanism, and procedures are carried out after returned to the rest of the statement, I think the original poster is too much description, don't know what I want to ask questionsCodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html