cp_1_lect_41 - RECURSION In Functions Click to edit Master...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 5/10/10 RECURSION In Functions
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 22 Definition (Computer Science) A recursive function is one which calls itself. Recursive functions are useful in evaluating certain types of mathematical function. When a function calls another function and that second function calls the third function then this kind of a function is called nesting of
Background image of page 2
5/10/10 33 Factorial Calculation long int fact(int n) /* non-recursive */ { int t, ans; ans = 1; for(t=1; t<=n; t++) ans = ans*t; return(ans); } long int factr(int n) /* recursive */ {
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 44 How recursive functions When a function calls itself, a new set of local variables and parameters are allocated storage on the stack, and the function code is executed from the top with these new variables. A recursive call does not make a new copy of the function. Only the arguments are new. As each recursive call returns, the old local variables and parameters are removed from the stack and execution
Background image of page 4
5/10/10 55 Summing up the elements Algorithm Design:
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/07/2010 for the course CS&IS TA C162 taught by Professor Kavitha during the Spring '09 term at Birla Institute of Technology & Science.

Page1 / 18

cp_1_lect_41 - RECURSION In Functions Click to edit Master...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online