progQs

advertisement
1. Review Question: Loops
Write a program that will read in two positive integers from the user, a and b, and
determine whether or not either one is a multiple of the other (a is a multiple of b if there
exists some integer k such that a = k*y). If it is found that one integer is a multiple of
the other, you must print out the relation between the two integers. If neither number is a
multiple of the other, output a message indicating this. The tough part is that we are not
allowing you to use the % operator anywhere in your code.
For example, if we are given two integers 6 and 18, our program should output:
18 = 3*6
On the other hand, if we are given two integers 5 and 9, our program should output:
Neither number is a multiple of the other.
Remember, you are not allowed to use the % operator anywhere in your code for this
question.
2. Review Question: Loops and Boolean Expressions
Write a program which will sum a sequence of numbers from the keyboard. The program
should read an integer upper bound, lower bound, and maximum number of items to sum.
It should then read in a sequence of integers, summing the integers until:
-
It has summed the maximum number of items
The sum is larger than the upper bound
The sum is smaller than the lower bound
The program should display the final sum.
For example, say the upper bound is 23, the lower bound is -35, and the maximum
number of items is 7. Then the program could read in the following sequence of numbers:
15 -4 -5 0 43
before displaying:
The final sum is 49.
Similarly, say the upper bound is 23, the lower bound is -35 and the maximum number of
items is 7. Then the program could read in the following sequence of numbers:
-4 -10 -1 2 4 -2 13
before displaying:
The final sum is 2.
Suppose the upper bound is 10 and the lower bound is 10. Then the program should read
in no numbers because it is already below the lower bound (since it starts at 0). It should
display:
The final sum is 0.
Do not use the break() instruction in your program.
Download