Outline for April 18, 2025
Reading:
zyBook text
§6.16, 10
Due:
Homework #2, due April 30, 2024
C compiler structure
C preprocessor
#include
#define
[
macros.c
]
#undef
Predefined macros
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 greatest common divisor
Go through Euclidean algorithm for computing gcd
Walk through function
gcd
, with
m
= 4 and
n
= 6
Do it again with
m
= 126 and
n
= 28
Go through program [
gcd.c
]
Recursive palindrome program
Go through algorithm, working from outside in
Write recursive case
Write base case
Put them together in [
ispal.c
]
Tower of Hanoi [
tower.c
]
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email:
mabishop@ucdavis.edu
ECS 36A, Programming & Problem Solving
Version of April 17, 2025 at 3:05PM
You can also obtain a PDF version of this.