CS 110: Elements of Computing. Instructor: Jim Aspnes


Homework Four Solutions

Due Friday, October 11th, 2002, at 5:00pm.

Original assignment.

Your task

Do problems 7, 8, and 26 from pages 198--200 of Brookshear.

For some of these problems, you will need to write a left arrow to represent assignment; we recommend using a less than sign and hyphen, like this: x <- x + 1.

Submitting your solution

Write up an email message containing your full name and the answer to these problems in plain text format (this means no HTML or Microsoft word documents), and send it to aspnes+110-02-4@cs.yale.edu. (Note: this is not the same email address as for previous homework.)

Solution:

Problem 7:
    Count <- 2
    repeat
	print the value assigned to Count
	Count <- Count + 1
    until Count > 6
Problem 8:
    Count <- 1
    while Count < 5
	print the value assigned to Count
	Count <- Count + 1
Problem 26:
The body of the loop consists of the lines
(print the value assigned to Count and
Count <- Count + 3)
It is executed twice. If the test is changed to Count not 6, the loop does not terminate, and the program prints out 1, 4, 7, 10, 13, 16, 19, etc.

Fri 20 Dec 2002 16:31:37 EST hw4.solutions.tyx Copyright © 2002 by Jim Aspnes