A recursive function is a function that calls itself. This function will continue to run until the stop condition is met, therefore in a recursive function needs to be there are 2 important blocks, namely block that became the point stop from a process of recursion and the block that is calling itself.
Example of a recursive implementation:
1. the functions of the print to the screen
This function prints the value of the parameter that is thrown to him. If the value of the parameter > 0, the function will print the value of the parameter and then calls her again, otherwise, the program stops.
This function prints the value of the parameter that is thrown to him. If the value of the parameter > 0, the function will print the value of the parameter and then calls her again, otherwise, the program stops.
2. power Functions
This function is used to calculate the value: Xn with n a positive integer. The solution of the matter:
IF n = 1, THEN Xn = X
In ADDITION: Xn = X * Xn-1
For example taken value of X = 5 to n = 3, a depiction of the process of solving them:
Rank function: example
a is the number dipangkatkan, while b is the number pemangkatnya. If the value of b is 1, return a, other return a multiplied by the power function with parameters a and b-1. For more details, apply in the program.
This function is used to calculate the value: Xn with n a positive integer. The solution of the matter:
IF n = 1, THEN Xn = X
In ADDITION: Xn = X * Xn-1
For example taken value of X = 5 to n = 3, a depiction of the process of solving them:
Rank function: example
a is the number dipangkatkan, while b is the number pemangkatnya. If the value of b is 1, return a, other return a multiplied by the power function with parameters a and b-1. For more details, apply in the program.
3. the function factorial
The factorial can be made to implement recursion. The following is a recursive factorial function of a program.
The factorial can be made to implement recursion. The following is a recursive factorial function of a program.
Comments :
0 comments to “Recursive Function”
Post a Comment