Assignment #1

Introductory C Programming

UW Experimental College


Assignment #1

Handouts:

Syllabus
Assignment #1
A Short Introduction to Programming
A Brief Refresher on Some Math Often Used in Computing
Class Notes, Chapter 1
Class Notes, Chapter 2
Available Compiler Options
Common Compiler Error Messages and Other Problems
Compiling C Programs: Step by Step

Reading Assignment:

A Short Introduction to Programming
Class Notes, Chapter 1
Class Notes, Chapter 2 (optional)
Compiling C Programs: Step by Step

Review Questions:

  1. Approximately what is the line #include <stdio.h> at the top of a C source file for?
  2. What are some uses for comments?
  3. Why is indentation important? How carefully does the compiler pay attention to it?
  4. What are the largest and smallest values that can be reliably stored in a variable of type int?
  5. What is the difference between the constants 7, '7', and "7"?
  6. What is the difference between the constants 123 and "123"?
  7. What is the function of the semicolon in a C statement?

Exercises: (easy to harder; do as many as you like, but at least two)

1. Get the ``Hello, world!'' program to work on your computer. If you're using a Unix machine, the instructions in the notes should get you started. If you're using a commercial compiler on a home computer, the compiler's instruction manuals should (really, must) tell you how to enter, compile, and run a program. (In either case, the ``Compiling C Programs'' handout should help, too.)

2. What do these loops print?

for(i = 0; i < 10; i = i + 2)
	printf("%d\n", i);
for(i = 100; i >= 0; i = i - 7)
	printf("%d\n", i);
for(i = 1; i <= 10; i = i + 1)
	printf("%d\n", i);
for(i = 2; i < 100; i = i * 2)
	printf("%d\n", i);

3. Write a program to print the numbers from 1 to 10 and their squares:

	1	1
	2	4
	3	9
	...
	10	100

4. Write a program to print this triangle:

	*
	**
	***
	****
	*****
	******
	*******
	********
	*********
	**********
Don't use ten printf statements; use two nested loops instead. You'll have to use braces around the body of the outer loop if it contains multiple statements:
	for(i = 1; i <= 10; i = i + 1)
		{
		/* multiple statements */
		/* can go in here */
		}
(Hint: a string you hand to printf does not have to contain the newline character \n.)



This page by Steve Summit // Copyright 1995-9 // mail feedback