Problems: In this lab, you are to write solutions to the following two problems. In each case, turn your solutions utilizing the course's specified format for submitting assignments.
Write a program that reads the sitter's starting time in hours and minutes and the ending time in hours and minutes and then computes the sitter's fee. Assume all times are between 6:00 pm and 6:00 am; hours should be entered as numbers on a 12-hour clock, so that hour 3 should be considered as 3:00 am and hour 8 should be considered as 8:00 pm. Hours outside the range 0 to 12 should be considered invalid.
[Note: You may not use a 24 hour clock for this problem. Also, times must be given in hours and minutes (as two nonnegative integer values).]
Let N and M be two positive integers. The greatest common divisor of N and M, denoted gcd (M, N), is defined to be the positive integer D such that
For example, 2 = gcd (6, 8); 4 = gcd (4, 12); 1 = gcd (8, 9); 6 = gcd (66, 24).
Algorithm: The algorithm proceeds by long division -- keeping track of subsequent remainders:
This process continues until we find a remainder Ri+1 which is 0. Then Ri = gcd (M, N).
Example:
Thus, 6 = gcd (66, 24).
This document is available on the World Wide Web as
http://www.cs.grinnell.edu/~walker/courses/195.fa01/lab-intro-C.html
|
created August 31, 1998 last revised September 14,2001 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |