CS21 Week1 In-Class Exercises

  1. The following program was written without comments or instructions to the user, except for a prompt. Save the program.

    w01-mystery.c

    Then open it in emacs and read through it to figure out what it is doing. What result is it calculating? Rewrite this program so it is easier to understand, both for the user and the programmer who must modify it in the future. Compile it and execute it.

  2. The following program is meant to calculate the average of two numbers entered by the user. Unfortunately it has some bugs. Your job is to correct them. Save the program.

    w01-buggy.c

    Edit the program to correct the mistakes. Remember to save the file after you change it and before you try to re-compile it. Keep track of each bug you find. Which ones are syntactic errors and which one are logical errors?

  3. Once you finish the above exercises you can work on your homework for this week.