Solution for Exercise 10-9
ex1009
#include <stdio.h> float convert(float f); int main() { float temp_f,temp_c; printf("Temperature in Fahrenheit: "); scanf("%f",&temp_f); temp_c = convert(temp_f); printf("%.1fF is %.1fC\n",temp_f,temp_c); return(0); } float convert(float f) { float t; t = (f - 32) / 1.8; return(t); }
Notes
* I used the underscore in temp_f
and temp_c
to avoid having f
and c
as variable names. I wanted to use fahrenheit
and celsius
as the names, but it made the printf() statement too long and it would have wrapped and looked ugly in the book.
* Don't let the %.1f
conversion character vex you. It's still the %f
conversion character, but with extra arguments between the %
and f
. Also, the big F
afterwards might look confusing, but it's considered just another character in the string and not part of the conversion character.
Copyright © 1997-2024 by QPBC.
All rights reserved