#include <stdio.h>
// Function prototypes
double toCelsius(double fahrenheit);
double toFahrenheit(double celsius);
// Function definitions
/**
* Function Name: toCelsius
*
* Function Block:
* Converts a Fahrenheit temperature to its Celsius equivalent.
*
* @param fahrenheit The temperature in Fahrenheit.
* @return The equivalent temperature in Celsius.
*/
double toCelsius(double fahrenheit) {
return (fahrenheit - 32) * 5.0 / 9.0;
}
/**
* Function Name: toFahrenheit
*
* Function Block:
* Converts a Celsius temperature to its Fahrenheit equivalent.
*
* @param celsius The temperature in Celsius.
* @return The equivalent temperature in Fahrenheit.
*/
double toFahrenheit(double celsius) {
return (celsius * 9.0 / 5.0) + 32;
}
int main() {
// Print Celsius to Fahrenheit table
printf("Celsius\t\tFahrenheit\n"); for (int celsius = 0; celsius <= 100; celsius++) {
printf("%d\t\t%.1f\n", celsius
, toFahrenheit
(celsius
)); }
// Print Fahrenheit to Celsius table
printf("\nFahrenheit\tCelsius\n"); for (int fahrenheit = 32; fahrenheit <= 212; fahrenheit++) {
printf("%d\t\t%.2f\n", fahrenheit
, toCelsius
(fahrenheit
)); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBGdW5jdGlvbiBwcm90b3R5cGVzCmRvdWJsZSB0b0NlbHNpdXMoZG91YmxlIGZhaHJlbmhlaXQpOwpkb3VibGUgdG9GYWhyZW5oZWl0KGRvdWJsZSBjZWxzaXVzKTsKCi8vIEZ1bmN0aW9uIGRlZmluaXRpb25zCi8qKgogKiBGdW5jdGlvbiBOYW1lOiB0b0NlbHNpdXMKICogCiAqIEZ1bmN0aW9uIEJsb2NrOgogKiBDb252ZXJ0cyBhIEZhaHJlbmhlaXQgdGVtcGVyYXR1cmUgdG8gaXRzIENlbHNpdXMgZXF1aXZhbGVudC4KICogCiAqIEBwYXJhbSBmYWhyZW5oZWl0IFRoZSB0ZW1wZXJhdHVyZSBpbiBGYWhyZW5oZWl0LgogKiBAcmV0dXJuIFRoZSBlcXVpdmFsZW50IHRlbXBlcmF0dXJlIGluI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