11 - ICS 103: Computer Programming in C Handout-11 Topic:...

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

View Full Document Right Arrow Icon
ICS 103: Computer Programming in C Handout-11 Topic: Recursive Functions. Objective : What is Recursive Function ? :         Recursive functions are the functions which call themselves repeatedly until some condition is  met and then the function stops calling itself and returns to the caller.   A recursive function has two parts :         1- Base case (stopping condition)         2-Recursive case :which must always get closer to base case from   one invocation to another.                          e.g                        1   for n=0  (base case)           n!=                          n*(n-1)!  for  n>0  (general case) A recursive solution always need a stopping condition to prevent an infinite loop and we achieve it by using base case. e.g   power(int x, int y)       {         if(y==0) return 1;  /* base case */         else            return (x*power(x,y-1));  /*general case */        } Any problem which we can solve using recursion, we can also solve that problem using iteration.         Generally, a recursive solution is slightly less efficient, in terms of computer time, than an  iterative one because of the overhead for the extra function calls. In many instances, however, 
Background image of page 1

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

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

This note was uploaded on 05/09/2010 for the course ICS 102 taught by Professor Zaman during the Spring '10 term at Abilene Christian University.

Page1 / 4

11 - ICS 103: Computer Programming in C Handout-11 Topic:...

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

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