Write a recursive function to find the value of the piecewise

The clearance required to write Fun recursive function (n) to implement the function Fun shown below, wherein n is a positive integer, if the input is not a positive integer, output "non-positive integer."
Here Insert Picture Description

related information

What is a recursive function

I.e., from the recursive function calls the function, in the functions that calls itself directly or indirectly, i.e. nesting function calls is the function itself.

Description of function call mechanism

Defined between any of the functions can not be nested, independent of each other (one another can be called) between the calling function and the callee function. Function call occurs, the called function in the protection of environment and the operation function call return address, so that the state of the calling function may be fully restored after the operation is returned to the called function, and regardless of the state of the called function.
The code is run, although the called function is a function of the same body of code, but the point of call, the call state, returns at different points, can be seen as a copy function, regardless of the code calls the function, the code function is independent. Stack space is running the called function is independent of the function call stack space, so the call data between functions is irrelevant. By passing parameters and return values to the links between functions, considered as a black box function.

In the form of recursive calls

Recursive call recursive call direct and indirect recursive calls in two forms.
Direct recursive function calls itself appears in the function.
Indirect recursive call is a function call other functions, but other functions which call this function.

Programming requirements is to present related programming tasks complement step1 / RecSegFunCal.cpp file Fun function to achieve the required segment seeking function values.

int Fun(int n)
{
    if(n<=3)
 {
  return n;
 }
 else
 {
  return Fun(n-1)+Fun(n-3);
 }
}
Published 102 original articles · won praise 93 · views 4961

Guess you like

Origin blog.csdn.net/huangziguang/article/details/104783908