Lab #4: Simple Exercises in the C Programming Language

Assigned: Thu 21 Feb 02
Due: Thu 28 Feb 02

About this lab

This week's lab will be the first of a couple of studies of individual programming languages we will make over the course of the term. The character of these labs will be quite different from the earlier, implementation-oriented labs: rather than solving a significant problem about languages using a known vehicle (Java), you will be solving smaller problems of more general character using a new language. The point, of course, is to familiarize you with some of the features of these new languages, although you will not be able to get any significant experience from a few small problems. Rather, you should try to concentrate on the novel features of these languages and how they affect your programming tasks.

Unfortunately, our textbook does not provide any consolidated description of the C language, so we will need to depend on some other reference books and on-line materials for background on C: I have placed several links to good references on the course homepage, as shown in lecture.

In addition to these reference materials, you will need to settle on a C compiler to use for your work and find out how to call it. Although there are several compilers available on the Gemini/Hudson systems, I recommend the gcc demonstrated in class. You may also want to use a C compiler on Windows, which may come with a more graphical interface. Your particular choice of compiler is not too important, since we will not be making use of any too-sophisticated features.

Basics of C programming

As described in lecture, there are a number of tricky points of C syntax and semantics which you will have to overcome in order to get through even the most basic programs. Syntactically, C is rather like Java (of course, historically C came first), but here's a quick list of difference which are likely to be difficult at first:

Programming problems

Write solutions to each of the following problems. Remember that the point of these exercises is to help you get familiar with the language, not to be the best algorithm or the most useful program, or to have the slickest interface. When you demo and hand in your program, be sure to document which platform and compiler you used. You should also provide a short (small paragraph) summary of your reaction to C and your prior exposure, if any. You can include this information in a comment at the top of one of the programs if you like. solution