You are on page 1of 1

University of Regina

Department of Computer Science


CS110- Assignment 3

Exercises
(NO programming required; Your submission should be a .doc, .docx, .odt, .pdf, … document, or a .bmp, .png, .jpg, … image or scan
of your work; 2 Marks)

1. Write a loop to print the first 10 powers of 3, namely 30 = 1, 31 = 3, 32 = 9, ..., 39 = 19683.

2. Write an if-else statement to print the (double) quotient of 1/x, if, for a given integer x, x ≠ 0, and to print “ERROR” otherwise.

3. Given the following snippet of code, how many times the code outputs the sum of i, j, and k.
for (int i= 0; i<10; i++) for (int j= 0; j<10; j++) for (int k= 0; k<10; k++)
cout << i << " + " << j << " + " << k << " = " << i+j+k << endl;

Programming

1. Write a program to compute, and output to the screen, the terms of a sequence as it converges to 0. The sequence begins with a
value k and is then repeatedly divided by 4 until it is (essentially) equal to 0. For example, the sequence induced by k = 12 is 12/4 = 3,
3/4 = 0.75, 0.75/4 = 0.1875, 0.1875/4 = 0.046875, 0.046875/4 = 0.01171875, ... Your submission should include a screenshot of the
execution of the program using each of the values k = 7, 0.1 and 1.9.

2. 1. Write a program to determine, and output to the screen, the class of an earthquake, given its magnitude. A class of minor is
given for those in the range of [0, 4), light if in [4, 5), moderate if in [5, 6), strong if in [6, 7), major if in [7, 8) and great if in [8, ꝏ).

You might also like