In: Computer Science
C language <stdio.h> ONLY USE double and const int
Write a program to convert Celsius temperature to Fahrenheit temperature. The formula for converting Celsius temperature into Fahrenheit temperature is:
F = (9 / 5) * C + 32
Create integer constants for the 3 numbers in the formula (9, 5, and 32). Follow the 3 steps in the Information Processing Cycle - Input, Processing, and Output. Convert the 9 to a double when converting the temperature (use type casting). Have a blank line in the output between the formula and the input. Display the converted temperature to 1 decimal place (and don't forget the ending period).
Have a blank line at the end of your program to separate the last line of output from your program from the "Press any key to continue . . .", and do this for all programs that you write.
Example Run #1:
(bold type is what is entered by the user)
Fahrenheit temperature is converted from Celsius temperature by
the formula:
F = (9 / 5) * C + 32
Enter the Celsius temperature: 28
The converted Fahrenheit temperature is xx.x degrees.
The example run shows EXACTLY how your program input and output will look.
#include<stdio.h>
void main()
{
const int x=9;
const int y=5;
const int z=32;
double celsius;
/* taking input from the user*/
printf("Enter the Celsius temperature: ");
scanf("%lf", &celsius);
/* convert Celsius temperature to Fahrenheit temperature
processing*/
/* F = (9 / 5) * C + 32*/
printf("\n");
double F= ((double)x/y) * celsius + z; /* converted const int into
double for x*/
printf("The converted Fahrenheit temperature is %0.1f degrees.\n",
F);
/* 0.1f in above print function will print only one decimal
value*/
}
/* note: refer the following figure */