|
CS256 - Fundamentals of Structured Programming
| Displaying exercises/e4/solution/h4.c
#include <stdio.h>
/**
* Print a prompt "Input degrees F: " and accept a double input
* and convert the input to degrees Celsius and print it out to
* two decimal places.
* Example input/output:
* ./h1
* Input degrees F: 90
* Degrees C = 32.22
*/
int main(void)
{
// These must be double according to the specification above.
double F, C;
printf("Input degrees F: ");
scanf("%lf", &F);
// Using 5.0/9.0 makes each number floating point, so the division is floating
// point. Using 5/9 is integer division (result = 0) since both numbers would
// be integers.
C = (F-32) * (5.0/9.0);
printf("Degrees C = %.2f\n", C);
return 0;
}
|