| CSC 201 | Grinnell College | Spring, 2005 |
| Data Representation, Memory Management, and Formal Methods | ||
This laboratory exercise provides practice with basic elements of the C programming language. Specifically, the lab emphasizes conditional (if) and looping (for, while) constructs.
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, and hours should be entered as being between 0 and 12 (inclusive). Hours outside the range of 0 to 12 should be considered invalid.
The following table may clarify allowed time values for this problem.
| Starting | Starting | Ending | Ending | Starting | Ending |
|---|---|---|---|---|---|
| Hour | Minutes | Hour | Minutes | Time | time |
| 8 | 0 | 3 | 30 | 8:00pm | 3:30am |
| 6 | 0 | 0 | 45 | 6:00pm | 12:45am |
| 12 | 0 | 6 | 0 | 12:00am (midnight) | 6:00am |
Additional Notes:
As illustrated in this table, an hour of 0 or 12 is interpreted the same, as midnight.
You may not use a 24 hour clock for this problem.
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/201.sp05/lab-intro-c.html
|
created August 31, 1998 last revised February 11, 2005 |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |