Read: 3.3 and 3.4.
Do: 3.8.9, 3.8.10
Program:
Enter bingo: 4 1 2 3 4 Bingo!
Enter starCount: 12 Enter lineSize: 5 ***** ***** **
Extra Credit: print out the number of stars printed. For example:
Enter baseSize: 4 **** *** ** * Extra Credit: 10 stars printed.
In this program we will solve the problem of placing an integer in
reduced form. Recall that a fraction i/j
is in reduced form if there
are no common divisors in i and j. So 2/5 is in reduced form, but 2/6
is not. The fraction 2/6 is equal to 1/3, and 1/3 is in reduced form.
The algorithm for this problem was known 2500 year ago and is today
called the Euclidean
Algorithm. It is a considerable challenge for
someone to come up with this algorithm all by themselves!
Write the program Euclidean.C which accepts two integers called
i and j and finds the greatest common divisor of the two.
This is what they would each have to be divided by to place
i/j
in reduced form.
Check that i is not negative and j is neither negative nor zero,
and exit with a message to the user if this is not true.
For example:
Enter integer i: 85 Enter integer j: 153 The lowest common divisor is 17