CS21 Week3 Tuesday In-Class Exercises

  1. Make a week3 subdirectory in your cs21 directory:
        % cd
        % cd cs21
        % mkdir week3
        % cd week3
        % pwd
    
    then copy these files to your week3 subdirectory:
        % cp ~newhall/public/cs21/week3/* .
    

  2. We are going to look over factorial.c together, so start by opening factorial.c in emacs (or vi). The '&' at the end of the command line means that emacs should be run in the background (i.e. the Unix shell will give you back the prompt to run other commands while emacs is running). Any program that pops up its own window (like gvim or firebird) is a good candidate for running in the background.
    % emacs factorial.c &
    
    % gvim factorial.c &
    

    After we examine it in class, try running it. Try running it for different input values. What happens when n is large? why? how can you fix this?

  3. Open up squares.c in emacs (or vi).
        % emacs squares.c &
    
    Examine the code. Once you understand what it is doing, compile and run it. Does the program's output make sense to you? I'll step through this execution in class.