|CSC 161||Grinnell College||Spring, 2010|
|Imperative Problem Solving and Data Structures|
This laboratory exercise provides practice with reading data, computing, and printing within a C program.
Consider the program quarts-1.c from the annotated program in today's reading.
Write a program that reads a person's weight in pounds and computes (and prints) the weight in grams (1 pound avoirdupois = approximately 453.59 grams).
Run your program with a few test cases. What values might you test (ideally, they should exercise the program's capabilities but be easy for you as programmer to check)?
Each of the following programs reads two numbers using scanf, using different format variations.
Click on each program, save it, compile it, and run it with the suggested input variations. For each test case, explain what values are read and why the scanf assigns the given values to the variables.
Write a program to read a person's height in feet and inches and print the person's height in centimeters (1 inch = approximately 2.54 centimeters). The output of the program should present an equation of the form:
5 feet 6.2 inches = 168.15 centimeters
That is, the number of feet should be given as an integer, the number of inches to 1 decimal place, and the number of centimeters to 2 decimal places. One space should separate each number from text or the equal sign.
Write a program that reads the radius of a circle and prints the circle's area and circumference in the format illustrated below:
radius area circumference 2.5 19.63 15.71
That is, the radius, area, and circumference should appear under headings, the radius should be printed to 1 decimal place, and the area and circumference to 2 decimal places.
Write a program that reads the coefficients a, b, c of a quadratic equation: a x2 + b x + c = 0, and prints the roots of the equation to two decimal places.
Do King, Programming Project 3.1 (page 50).
Hint: Check the comments for %5.3d format on page 40.
Do King, Programming Project 3.2 (page 50).
This document is available on the World Wide Web as
created 13 May 1998
last revised 9 January 2010
|For more information, please contact Henry M. Walker at firstname.lastname@example.org.|