CSCI 1320 (Principles of Algorithm Design I), Fall 2008:
Homework 2

Assigned:
September 18, 2008.

Due:
September 25, 2008, at 5pm.

Credit:
40 points.

Reading

Be sure you have read (or at least skimmed) chapters 1, 2, and 3 of the textbook.

Programming Problems

Do the following programming problems. You will end up with at least one code file per problem. Every code file should begin with comments identifying you as the author and describing its purpose. It should be readable to human readers as well as to the compiler, so use consistent indentation and meaningful variable names. Feel free to cut and paste code from any of the sample programs on the course Web site.

Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu, with each file as an attachment. Please use a subject line that mentions the course number and the assignment (e.g., ``csci 1320 homework 2''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.

  1. (20 points) Write a C program to convert a Fahrenheit temperature to Celsius. The rule for converting Fahrenheit temperature F to Celsius temperature C is
    C = (5/9)(F - 32)
    The program should ask the user for the Fahrenheit temperature and print the equivalent Celsius temperature. You can use integers or floating-point numbers for this problem.

  2. (20 points) Write a C program that prompts the user for a number of seconds S (S should be a non-negative integer, but your program does not need to check for that) and prints S in a more normal notation -- years, days, hours, minutes, and seconds. You may ignore leap years and seconds. For example, 100 seconds is 1 minute and 40 seconds. (You may be interested to run this program using successive powers of 10 as input and see how long it takes before seconds start to add up to years.)



Berna Massingill
2008-09-18