Write a program to take a depth (in kilometers) inside the earth as input data;
ID: 670657 • Letter: W
Question
Write a program to take a depth (in kilometers) inside the earth as input data; compute and
display the temperature at this depth in degrees Celsius and degree Fahrenheit. The relevant
formulas are:
celsius = 10*depth + 20 (Celsius temperature at depth in km)
fahrenheit = 1.8*celsius + 32.
You should include four functions in your program.
1.void print_introduction (void)
2.double celsius_at_depth (double depth)
3.double celsius_to_fahrenheit (double celsius)
4.void print_conclusion(double depth)
Explanation / Answer
#include<stdio.h>
/*Function Declaration*/
doublecelsiusAtDepth;
doublecelsiusToFahrenheit;
voidprintResults;
intmain()
{
doubledepth;
printf("Entera depth value:");
scanf("%lf",&depth);
doublecelsius=celsuisAtDepth;
doublefahrenheit=celsiusToFahrenheit(celsius);
PrintResults(celsius,fahrenheit);
return(0);
}
/*Celsius=10*depth=20*/
doublecelsiusAtDepth (doubledepth)
{
return(10*depth+20);
}
/*Fahrenheit=((18.0/10.0)*celsius+32)*/
doublecelsiusToFahrenheit (doublecelsius)
{
return((18.0/10.0)*celsius+32);
}
/*FunctionprintResults should take in the two temperatures and print them.*/
void printResults(double celsius,doublefahrenheit)
{
printf("Celsius:%lf Fahrenheit: %lf ", celsius, fahrenheit);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.