CSIE: Introduction to Computers (I)

Homework 4, Due 12/7

1. Page 98, Exercise 3.34. (25%)

2. Page 98, Exercise 3.36. (25%)

3. Page 99, Exercise 3.46. (25%)

4. Write a program that inputs two integers, determine the g.c.d (greatest common divisor) of them, and output the result.  A g.c.d. can be obtained by repeatedly dividing the larger integer by the smaller integer, and replacing the larger integer by the remainder such that the new larger integer is the old smaller integer and the new smaller integer is the remainder until the remainder is zero.  Then the last remainder is the g.c.d.  For example, suppose the two integers are 112 and 88:

112 % 88 = 24

88 % 24 = 16

24 % 16 = 8

16 % 8 = 0

Then the g.c.d is 8.  (25%)