Lecture 11: October 18, 2019
Reading
:
C text
, §9
Due
: Extra Credit #1: due October 21, 2019; Homework #2, due October 24, 2019
Greetings and felicitations!
When you upload your file to Canvas, it may append a number. That’s fine.
For problem 4, there should be
one
drawn rectangle, and it surrounds the rectangle with the given dimensions.
Recursion
Expressing a problem in terms of a simpler version of itself — use
n
!
Function calling itself
Similar to mathematical induction, but backwards
Structure: base case, recursive case
What happens if you omit the base case? (Bad things …)
How it works
Program stack
Walk through
nfact.c
, with
n
= 4
Note
nfact
calls
nfact
Recursive palindrome program
Go through algorithm, working from outside in
Write recursive case
Write base case
Put them together in
ispal.c
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
[email protected]
ECS 36A, Programming and Problem Solving
Version of October 18, 2019 at 10:57PM
You can also obtain a PDF version of this.