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

Assigned:
October 16, 2008.

Due:
October 30, 2008, at 5pm.

Credit:
40 points.

Reading

Be sure you have read chapter 4. You may also find section 6.9 helpful.

Programming Problems

Do the following programming problems. You will end up with at least one code file per problem. 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 4''). 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 that defines and tests a function for converting Fahrenheit temperatures to Celsius. (So you should be able to reuse some of your code from Homework 2.) Your program should include three functions:

  2. (20 points) Write a C program to perform a countdown using a recursive function. The program should prompt the user for two positive integers, a starting point S and a decrement D, and ``count down'' starting with S and decrementing by D, printing each number until a negative number is reached (which should not be printed). Output should look something like the following:

    Your program should print an appropriate error message if the user enters something other than integers, or if both numbers are not positive. (Think for a minute about what would happen if D were zero!)

    You can do this problem using various kinds of loops, but to get full credit you must use a recursive function. You'll probably want one that takes two parameters, a starting point and a decrement, and doesn't return anything, but has the side effect of printing all values from the first parameter down through the last value to print.



Berna Massingill
2008-10-23