Homework 15: First functions
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Wednesday, February 22
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw15
and submit using the204sub
command. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Sections 1 (writing functions) and 2 (function design) from the Unit 5 notes,
-
Write a program called
average.c
that reads in three numbers and prints out their average.Write and use a function with the following prototype to compute the average:
double average(double x, double y, double z);
Example runs:
roche@ubuntu$
./average
Enter three numbers:
1 2 3
The average is 2
roche@ubuntu$
./average
Enter three numbers:
2.1 2.1 2.1
The average is 2.1
roche@ubuntu$
./average
Enter three numbers:
8 6 12
The average is 8.66667