Skip to main content
Logo image

Section 12.3 Practice Your Functions!

The best way to get more comfortable with functions is to simply practice writing code. So here we go!

Subsection 12.3.1 Functions: Your Turn!

Activity 12.1.

Write a C program that converts temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit, depending on user input. Here is a sample session:
Please enter a temperature: 45 F
45 degrees Fahrenheit correspond to approximately 7.2 degrees Celsius.
And another sample session:
Please enter a temperature: 28 C
28 degrees Celsius correspond to approximately 82.4 degrees Fahrenheit.
The overall structure of the program is provided for you below. Your program should use functions for the temperature conversions: one for Fahrenheit to Celsius, and another for Celsius to Fahrenheit.

admin.....open in new window

Subsection 12.3.2 Another One!

Activity 12.2.

Write a function factorial() that accepts an integer as an argument and returns an integer, namely the factorial of the argument. A test program has already been provided for you below; you only need to write the function itself and add the prototype and the function call to the program.

admin.....open in new window