Chapter 4 exercise set 2

Divisible by 2 or 3

Submitted by George Ung.

Write a program that prints out each number from 2 to 20 and writes whether the number is divisible by 2 or 3, both, or neither. The output should look like this:

Num   Div by 2 and/or 3?
---   ------------------
2            by 2
3            by 3
4            by 2
5            neither
6            both
7            neither
8            by 2
9            by 3
10           by 2
11           neither
12           both
13           neither
14           by 2
15           by 3
16           by 2
17           neither
18           both
19           neither
20           by 2

First multiple of 7

Write a program that traverses a list of numbers and prints out the first number in the sequence that is a multiple of 7 (hint: you may want to use a break statement for this) for the message, “No multiples of 7 found.” if none of the values in the list are multiples of 7.