Recursion in Programming - tccicomputercoaching.com

Page 1

Recursion in Programming - tccicomputercoaching.com Recursion is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem. Such problems can generally be solved by iteration, but this needs to identify and index the smaller instances at programming time. Most computer programming languages support recursion by allowing a function to call itself from within its own code. To solve a problem recursively means that you have to first redefine the problem in terms of a smaller sub problem of the same type as the original problem.

Example, If we want to sum of 1 to 10 no without loop then we can use recursion like following: int sum(int n) { If (n == 1) { return 1; } else { return n + sum(n-1);


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.
Recursion in Programming - tccicomputercoaching.com by Rosario Riley - Issuu