I would like you to write a C Program to convert user input of the temperature i
ID: 3649428 • Letter: I
Question
I would like you to write a C Program to convert user input of the temperature in Fahrenheit to Celcius, Rankin(e), and Kelvininclude <stdio.h> //for printf and scanf
int main()
{
// Declare variables
double celsius, fahrenheit;
// Input
printf("Please enter a temperature in Fahrenheit: ");
scanf("%lf", &fahrenheit); // Read input from user, store in
// fahrenheit
fflush(stdin); // Flush input buffer
// Calculation
celsius = (5.0/9.0) * (fahrenheit - 32); // We must use 5.0
// because we are playing with floating point
// numbers and don't want to do integer division.
// Output
printf("%4.1f degrees fahrenheit = %4.1f degrees celsius ", fahrenheit, celsius); // Variables are given from left to right
getchar(); // For those icky windows compilers
return 0;
}
Explanation / Answer
#include main () { float temp_c, temp_f, temp_r, temp_k; printf ("Enter the value of Temperature in Fahrenheit: "); scanf ("%f", &temp_f); temp_c = ( temp_f - 32)/1.8; temp_r = (temp_f - 459.67); temp_k = (temp_f + 459.67)*5/9; printf ("The value of Temperature in Celsius is: %f", temp_c); printf ("The value of Temperature in Rankine is: %f", temp_r); printf ("The value of Temperature in Kelvin is: %f", temp_k); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.