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

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

Click to edit Master subtitle style 5/10/10 RECURSION In Functions

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

View Full Document
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
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 */ {

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

View Full Document
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
5/10/10 55 Summing up the elements Algorithm Design:

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

View Full Document
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
Ask a homework question - tutors are online