Otherwise the product of n and Factorialn 1 is returned Recursion Visualization

Otherwise the product of n and factorialn 1 is

This preview shows page 57 - 59 out of 59 pages.

Otherwise, the product of n and Factorial(n-1) is returned.
Image of page 57
Recursion Visualization Consider cout << n ! = " << Factorial(3) << endl; cout << "n! = " << Factorial(3) << endl; n = 3 n = 2 n = 1 n = 0 Factorial(3) = 3 * Factorial(2) = 3 * 2 = 6 Factorial(2) = 2 * Factorial(1) = 2 * 1 = 2 Factorial(1) = 1 * Factorial(0) = 1 * 1 = 1 Factorial(0) = 1 Activation records call Factorial(0) return 1 call Factorial(1) call Factorial(2) call Factorial(3) return 1 return 2 return 6
Image of page 58
Home works Home works Exercises 6.29 Exercises 6.30 Exercises 6.73 Exercises 6.78 Exercises 6.79 End of Chapter 6 End of Chapter 6
Image of page 59

You've reached the end of your free preview.

Want to read all 59 pages?

  • Winter '03
  • Pro.Lei
  • C++ Programming, Subroutine, formal parameter, circlearea

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture