Computer programming - Homework + Lab 1

Homework

1. Write a function that returns the median of three numbers (i.e., the middle one, when ordering the numbers by value).
Use conditional expressions. Avoid long and complex code. Test your code for all possible orderings of the arguments (how many?)

2. A really inefficient way of computing Fibonacci numbers is by using the recurrence directly as given: F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2.
Figure out how many calls are needed to compute Fn. Confirm by writing a program that also prints something in the function.

3. Write a program, similar to the one done in class, that draws the Koch curve, as described here.
Establish first what the parameters to your figure are. Orientation matters!

Compiling your program

Compiling and running are two distinct steps.
The compiler converts the source file (.c) to an executable file.
Command:  gcc  options   file.c
You should use these options (in any order) To run your program, use the command
./a.out
where . (dot) means the current directory (where you compiled), a.out is the executable file name (replace as needed) and / is the directory separator character under Linux.
Marius Minea
Last modified: Sun Sep 29 0:30:00 EEST 2013