// Program Name: Temperature Conversion Table
// Description: This program converts temperatures between Celsius and Fahrenheit and prints the results in tabular format.
// Converts from 0 to 100 degrees Celsius and from 32 to 212 degrees Fahrenheit.
#include <stdio.h>
// Function prototypes
float toCelsius(int theFahrenheitTemp);
float toFahrenheit(int theCelsiusTemp);
int main()
{
int i; // loop index
// Print header for Celsius to Fahrenheit table
printf("Celsius\t\tFahrenheit\n"); // Loop to print Celsius to Fahrenheit conversions from 0 to 100 degrees Celsius
for (i = 0; i <= 100; i++)
{
printf("%7d\t\t%6.1f\n", i
, toFahrenheit
(i
)); }
// Print header for Fahrenheit to Celsius table
printf("\nFahrenheit\tCelsius\n"); // Loop to print Fahrenheit to Celsius conversions from 32 to 212 degrees Fahrenheit
for (i = 32; i <= 212; i++)
{
printf("%10d\t%6.2f\n", i
, toCelsius
(i
)); }
return 0;
}
// Converts Fahrenheit temperature to Celsius
// Parameter: theFahrenheitTemp - the temperature in Fahrenheit to be converted
// Returns: the equivalent Celsius temperature
float toCelsius(int theFahrenheitTemp)
{
return (5.0 / 9.0) * (theFahrenheitTemp - 32);
}
// Converts Celsius temperature to Fahrenheit
// Parameter: theCelsiusTemp - the temperature in Celsius to be converted
// Returns: the equivalent Fahrenheit temperature
float toFahrenheit(int theCelsiusTemp)
{
return (9.0 / 5.0) * theCelsiusTemp + 32;
}
Ly8gUHJvZ3JhbSBOYW1lOiBUZW1wZXJhdHVyZSBDb252ZXJzaW9uIFRhYmxlCi8vIERlc2NyaXB0aW9uOiBUaGlzIHByb2dyYW0gY29udmVydHMgdGVtcGVyYXR1cmVzIGJldHdlZW4gQ2Vsc2l1cyBhbmQgRmFocmVuaGVpdCBhbmQgcHJpbnRzIHRoZSByZXN1bHRzIGluIHRhYnVsYXIgZm9ybWF0LgovLyBDb252ZXJ0cyBmcm9tIDAgdG8gMTAwIGRlZ3JlZXMgQ2Vsc2l1cyBhbmQgZnJvbSAzMiB0byAyMTIgZGVncmVlcyBGYWhyZW5oZWl0LgoKI2luY2x1Z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