|CSC 161||Grinnell College||Spring, 2009|
|Imperative Problem Solving and Data Structures|
This laboratory exercise provides practice with conditional (if) constructs in C.
When you started C in this course, we introduced the the Emacs Text Editor. In this lab, you are asked to use the the VIM editor for your work.
After this lab, you are free to use whatever editor you wish for writing your C programs. However, you are strongly encouraged to use either emacs or VIM, since these have powerful capabilities that can help with C programming.
Do King, Exercise 5.1 (page 93).
Do King, Exercise 5.3 (page 94).
Do King, Exercise 5.5 (page 94). (Be sure you can explain your answer!)
Do King, Programming Project 5.5 (page 96).
Do King, Programming Project 5.9 (page 97).
[This problem is based on an exercise by Darrah Chavey, Beloit College.]
Write a C program that reads the lengths of three sides of a triangle and prints out the classification of the triangle as follows:
In this problem, you should assume that the input values are all numbers, although error checking may indicate some numbers are negative or zero.
A nonnegative integer K is divisible by a positive integer L, if the remainder after dividing K by L is zero.
Write a program that reads two integers, M and N, and determines if either is a divisor of the other.
Hint: A list of C's arithmetic operators is given in Section 4.1 of King (page 54).
If x is a nonnegative number, then its square root may be computed directly by the sqrt function that is defined in C's math.h library. However, if x is negative, then its square root is a complex number (y i), where y2=|x| — that is, y is a square root of the absolute value of x.
Write a program that reads a real number x and computes its square root (x could be either negative or nonnegative).
(Challenge Problem — Optional)
A Baby Sitting Problem: A baby sitter charges $1.50 per hour until 9:00 pm (while the kids are still up), $1.00 per hour between 9:00 pm and midnight, and $1.25 per hour after midnight (since late night baby sitting interferes with morning classes).
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.
This document is available on the World Wide Web as
created 31 August 1998
last revised 25 January 2009
|For more information, please contact Henry M. Walker at email@example.com.|