Skip to content

Commit e227d4a

Browse files
committed
change readme
1 parent ae852e1 commit e227d4a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Chapter13/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ Why would you format your input rather than just having the file contain "the nu
111111
## [Review 14](review/14.txt)
112112
How do you plan the general layout of a graph? How do you reflect that layout in your code?
113113

114-
## [Exercise 1](exercise/01/01.cpp)
114+
## [Exercise 1](exercises/01/01.cpp)
115+
Here is another way of defining a factorial function:
116+
```
117+
int fac(int n) { return n>1 ? n*fac(n-1) : 1; } // factorial n!
118+
```
119+
It will do `fac(4)` by first deciding that since `4>1` it must be `4*fac(3)`, and that's obviously `4*3*fac(2)`, which again is `4*3*2*fac(1)`, which is `4*3*2*1`. Try to see that it works. A function that calls itself is said to be recursive. The alternative implementation in §13.5 is called iterative because it iterates through the values (using `while`). Verify that the recursive `fac()` works and gives the same results as the iterative `fac()` by calculating the factorial of 0, 1, 2, 3, 4, up until and including 20. Which implementation of `fac()` do you prefer, and why?

0 commit comments

Comments
 (0)