//**********************************************************************
// File: temperature_conversion.c
// -------------------------------
// This program demonstrates temperature conversion between Celsius and
// Fahrenheit using two functions:
//
// float toFahrenheit(int celsius);
// float toCelsius(int fahrenheit);
//
// The program prints two tables:
// 1. Celsius (0–100) to Fahrenheit (1 decimal place)
// 2. Fahrenheit (32–212) to Celsius (2 decimal places)
//
// Formulas used:
// F = (C * 9/5) + 32
// C = (F - 32) * 5/9
//
//**********************************************************************
#include <stdio.h>
// function prototypes
float toCelsius (int theFahrenheitTemp);
float toFahrenheit (int theCelsiusTemp);
int main()
{
int i; // loop index
//==============================================================
// Celsius to Fahrenheit Table
//==============================================================
printf("Celsius Fahrenheit\n"); printf("---------------------\n");
for(i = 0; i <= 100; i++)
{
// Convert Celsius to Fahrenheit using the function
float f = toFahrenheit(i);
// Print Celsius as integer, Fahrenheit with 1 decimal place
}
printf("\n\n"); // spacing before next table
//==============================================================
// Fahrenheit to Celsius Table
//==============================================================
printf("Fahrenheit Celsius\n"); printf("----------------------\n");
for(i = 32; i <= 212; i++)
{
// Convert Fahrenheit to Celsius using the function
float c = toCelsius(i);
// Print Fahrenheit as integer, Celsius with 2 decimal places
}
return 0;
}
//**********************************************************************
// Function: toCelsius
// -------------------
// Converts a Fahrenheit temperature to its Celsius equivalent.
//
// Formula:
// C = (F - 32) * 5/9
//
// Parameters:
// theFahrenheitTemp - an integer Fahrenheit temperature
//
// Returns:
// The temperature converted to Celsius (float)
//**********************************************************************
float toCelsius(int theFahrenheitTemp)
{
return (theFahrenheitTemp - 32) * 5.0 / 9.0;
}
//**********************************************************************
// Function: toFahrenheit
// ----------------------
// Converts a Celsius temperature to its Fahrenheit equivalent.
//
// Formula:
// F = (C * 9/5) + 32
//
// Parameters:
// theCelsiusTemp - an integer Celsius temperature
//
// Returns:
// The temperature converted to Fahrenheit (float)
//**********************************************************************
float toFahrenheit(int theCelsiusTemp)
{
return (theCelsiusTemp * 9.0 / 5.0) + 32.0;
}