#include <stdio.h>
float toCelsius(int theFahrenheitTemp);
float toFahrenheit(int theCelsiusTemp);
int main()
{
int i; // loop index
// Celsius to fahrenheit table
printf("Celsius to Fahrenheit:\n"); printf("-----------------------\n"); printf("Celsius Fahrenheit\n");
for (i = 0; i <= 100; i++)
{
printf("%2d %10.1f\n", i
, toFahrenheit
(i
)); }
// Fahrenheit to celsius table
printf("Fahrenheit to Celsius:\n"); printf("-----------------------\n"); printf("Fahrenheit Celsius\n");
for (i = 32; i <= 212; i++)
{
printf("%3d %11.1f\n", i
, toCelsius
(i
)); }
return 0;
}
//**************************************************************
// Function: toCelsius
//
// Purpose: Takes the fahrenheit temperature and converts it to celsius
//
// Parameters:
//
// theFahrenheitTemp - the temperature in fahrenheit
//
// Returns: theCelsiusTemp - the temperature in celsius
//
//**************************************************************
float toCelsius(int theFahrenheitTemp)
{
return (theFahrenheitTemp - 32) * 5.0 / 9.0;
} //toCelsius
//**************************************************************
// Function: toFahrenheit
//
// Purpose: Takes the celsius temperature and converts it to fahrenheit
//
// Parameters:
//
// theCelsiusTemp - the temperature in celsius
//
// Returns: theFahrenheitTemp - the temperature in fahrenheit
//
//**************************************************************
float toFahrenheit(int theCelsiusTemp)
{
return (theCelsiusTemp * 9.0 / 5.0) + 32;
}//toFahrenheit
I2luY2x1ZGUgPHN0ZGlvLmg+CgpmbG9hdCB0b0NlbHNpdXMoaW50IHRoZUZhaHJlbmhlaXRUZW1wKTsKZmxvYXQgdG9GYWhyZW5oZWl0KGludCB0aGVDZWxzaXVzVGVtcCk7CgppbnQgbWFpbigpCnsKCQogICAgaW50IGk7IC8vIGxvb3AgaW5kZXgKCiAgICAvLyBDZWxzaXVzIHRvIGZhaHJlbmhlaXQgdGFibGUKICAgIHByaW50ZigiQ2Vsc2l1cyB0byBGYWhyZW5oZWl0OlxuIik7CiAgICBwcmludGYoIi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tXG4iKTsKICAgIHByaW50ZigiQ2Vsc2l1cyAgICBGYWhyZ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