Coupon Accepted Successfully!



In programming there might be a situation where a function needs to invoke itself. The C++ language supports recursive feature, that is a function calls itself repetitively. In recursion a function calls itself and the control goes to the same function and it executes repeatedly until some condition is satisfied. In this type of recursive calls a function starts with a new value every time.

Rules for Recursive Function

  1. In recursion, it is essential to call a function by itself; otherwise recursion would not take place.
  2. Only the user-defined function can be involved in the recursion. Library function cannot involve in recursion because their source code cannot be viewed.
  3. A recursive function can be invoked by itself or by other function. It saves return address with the intention to return at proper location when return to a calling statement is made.
    The last-in-first-out nature of recursion indicates that stack data structure can be used to implement it.
  4. Recursion is turning out to be increasingly important in non-numeric applications and symbolic manipulations.
  5. To stop the recursive function, it is necessary to base the recursion on test condition, and proper terminating statement such as exit() or return() must be written using the if() statement.

7.24 Program to find the factorial of a entered number.



7.25 Program to calculate the gcd of two numbers.


Test Your Skills Now!
Take a Quiz now
Reviewer Name