Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

8.6 Recursion

Recursion is an advanced feature supported by C++ language. Recursion means a function calling itself. Consider the problem of finding a factorial of a number. In the example, we can clearly see that Fact(5) is calling Fact(4) and so on.

Fact(5) = 5 x 4 x 3 x 2 x 1
        = 5 x Fact(4)
        = 5 x 4 x Fact(3)
        = 5 x 4 x 3x Fact(2)
        = 5 x 4 x 3x 2 x Fact(1)
        = 5 x 4 x 3x 2 x 1 x Fact(0)
        = 5 x 4 x 3x 2 x 1 ( Fact(0) =1)


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial