Last active
August 29, 2015 14:09
-
-
Save sauntimo/ae260ce5697e4034409f to your computer and use it in GitHub Desktop.
Displays a table of Fahrenheit to Celsius and Celsius to Fahrenheit conversions - in a nice ASCII box :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* print Fahrenheit-Celsius table | |
for fahr = 0, 20, ..., 300; floating point version */ | |
print_table_top() | |
{ | |
printf("%c", 201); | |
print_line(24); | |
printf("%c\n", 187); | |
} | |
print_table_bottom() | |
{ | |
printf("%c", 200); | |
print_line(24); | |
printf("%c\n", 188); | |
} | |
print_line(length) | |
{ | |
int i; | |
for(i = 0; i <= length; i++) | |
printf("%c", 205); | |
} | |
main() | |
{ | |
float fahr, celsius; | |
int lower, upper, i; | |
lower = 0; /* lower limit of temperature table */ | |
upper = 300; /* upper limit of temperature table */ | |
printf("\n\nFahrenheit to Celsius Conversion Table\n"); | |
print_line(37); | |
printf("\n\n"); | |
print_table_top(); | |
for(fahr = 0; fahr <= upper; fahr = fahr + 20) | |
printf("%c %3.0f %c%s %6.1f %c%s %c\n", 186, fahr, 167, "F is ", (5.0 / 9.0) * (fahr - 32.0), 167, "C.", 186); | |
print_table_bottom(); | |
printf("\n\nCelsius to Fahrenheit Conversion Table\n"); | |
print_line(37); | |
printf("\n\n"); | |
print_table_top(); | |
for(celsius = 0; celsius <= upper; celsius = celsius + 20) | |
printf("%c %3.0f %c%s %6.1f %c%s %c\n", 186, celsius, 167, "C is ", ((9.0 / 5.0) * celsius) + 32.0, 167, "F.", 186); | |
print_table_bottom(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment