*This preview shows
page 1. Sign up
to
view the full content.*

**Unformatted text preview: **elf.
Specifically, if “factorial” calls itself, then
there are two parameters “n” that have
NOTHING to do with each other.
7 factorial(3):
factorial(2):
factorial(1):
factorial(0): n = 3 calls factorial(2)
n = 2 calls factorial(1)
n = 1 calls factorial(0)
returns 1 to factorial(1). Inside
factorial(1), 1 * factorial(0)
becomes:
1*1 factorial(1): returns 1 to factorial(2), Inside
factorial(2), 2 * factorial(1)
becomes:
2*1
8 factorial(2) returns 2 to factorial(3). Inside
factorial(3), 3 * factorial(2)
becomes:
3*2 A problem can be solved recursively if the
following conditions are fulfilled: So, inside factorial(3), the return value is
3 * 2 = 6. This is what will be returned to
the program. 1 - The problem can be decomposed into several
problems such that (at least) one of them is of
the “same kind” as the initial problem but
“simpler” and all the others are “easy” cout << factorial...

View
Full
Document