Our Christmas vacation is over. It is already a new year, thus we are entering a new lesson. It is not totally new because it is still programming but the lesson is harder than our past lessons. Last time, we discuss only the different conditions but now, we are focusing on a program that consist two or more functions aside from the main function. Isn’t in difficult???
Well, we have no choice but the study and remember the lessons that are being discussed to us because all of us want to pass this subject.
RECURSION is:
- The repetitive process by which a functions calls itself is called recursion or circular definition.
- This is a way of defining something in terms of itself.
- A function is said to be recursive if a statement in the body of the function calls the function that contains it.
Recursion also has its parts. And that are:
Base Case
- This is the part of the recursive function that is found on the if clause. This contains the condition that should be satisfied at one point of execution to terminate the repetitive process done by the recursive function.
General Case
-This is the part of the recursive function that is found on the else-clause. This contains the function call of the recursive function to itself.
- Direct Recursions are recursive functions that can call itself through a function call directly inside the body of the function.
- Indirect recursions are recursive functions that can call another functions outside its function.
EXAMPLES:
1.
factorial (int n)
2.
Give the output of the ff. program when the value entered for a=5.
solve (int a)
if (a = = 1) return 2;
No comments:
Post a Comment