11 - ICS 103 Computer Programming in C Handout-11 Topic Recursive Functions Objective To know about importance working use of recursive functions What

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

This preview shows page 1 - 2 out of 4 pages.

ICS 103: Computer Programming in C Handout-11 Topic: Recursive Functions. Objective : To know about importance, working & use of recursive functions. 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, 
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 4 pages?

  • Spring '10
  • zaman
  • Recursion, Control flow, base case, Recursive int power

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes