Solution for Exercise 10-10
ex1010
#include <stdio.h>
float convert(float f);
int main()
{
float temp_f;
printf("Temperature in Fahrenheit: ");
scanf("%f",&temp_f);
printf("%.1fF is %.1fC\n",temp_f,convert(temp_f));
return(0);
}
float convert(float f)
{
float t;
t = (f - 32) / 1.8;
return(t);
}
Output
Temperature in Fahrenheit: 98.6
98.6F is 37.0C
Notes
* Changes shown in this solution:
Line 7: The temp_c variable is no longer needed, so it's removed.
Lines 10-11: the original call to the convert() function is removed
Line 11: The printf() statement is modified to contain the call to the convert() function as its final argument.
* Some compilers may warn of an unused variable if you forget to remove the declaration for the temp_c variable.
Copyright © 1997-2026 by QPBC.
All rights reserved
