SI 204 Spring 2017 / HWs


This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

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 the 204sub command.
  • This is an electronic homework and you do not need to print out anything to turn in during class.

Assignment

  1. Required reading: Sections 1 (writing functions) and 2 (function design) from the Unit 5 notes,
  2. 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