Computer Science I

MC140.01 / MC140.02

Fall 2000

Assignment #4

due Friday 20 October 2000

The goal of this assignment is to practise some elements of C that people had trouble with on the first exam. The assignment is worth 4% of your term mark. It will be marked out of 40 points. (In place of doing this assignment, you may use your combined scores for the grid and truth table questions on the exam. This score is shown on the front of your exam, with a plus sign (``+'') in front of it, under your normalized exam score (which is probably circled).)

1. (20 points)

The diagram below shows a 2 X 2 grid containing four characters. Write a program to store the characters in a 2-dimensional array called grid without using loops.

grid =
x=0 x=1
y=0 A B
y=1 C D

2. (20 points)

Write a program that prints out a truth table for XOR. XOR is defined as follows:

x XOR y = (x AND y) NOR (x NOR y)


x NOR y = NOT (x OR y)

3. (0 points --- just for fun)

This problem is just for practise --- you don't need to hand anything in for this one. What is the exact output of the following code fragment? Include it in a program and see what you get! Try changing the end values of the loops and looking at the output.

int i, j;
for ( i=0; i<3; i++ ) {
  for ( j=0; j<2; j++ ) {
    printf( ``%d %d\n'', i, j );
4. Submission.

As usual, submit your program electronically. Not as usual, you will need to submit TWO programs, one for question 1 and one for question 2. So you should deposit TWO files in the professor's folder, named as follows:

e.g. sklarel-ass4-1.c
Bring a hardcopy to class of both programs. Please staple loose sheets together. Thank you.