Outline for April 18, 2025

Reading: zyBook text §6.16, 10
Due: Homework #2, due April 30, 2024


  1. C compiler structure

  2. C preprocessor
    1. #include
    2. #define [macros.c]
    3. #undef
    4. Predefined macros

  3. Recursion
    1. Expressing a problem in terms of a simpler version of itself — use n!
    2. Function calling itself
    3. Similar to mathematical induction, but backwards
    4. Structure: base case, recursive case
    5. What happens if you omit the base case? (Bad things …)

  4. How it works
    1. Program stack
    2. Walk through nfact.c, with n = 4
    3. Note nfact calls >nfact

  5. Recursive greatest common divisor
    1. Go through Euclidean algorithm for computing gcd
    2. Walk through functiongcd, with m = 4 and n = 6
    3. Do it again with m = 126 and n = 28
    4. Go through program [gcd.c]

  6. Recursive palindrome program
    1. Go through algorithm, working from outside in
    2. Write recursive case
    3. Write base case
    4. Put them together in [ispal.c]

  7. Tower of Hanoi [tower.c]

UC Davis sigil
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.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh