12-12-2004, 12:34 PM | #1 (permalink) |
Junkie
|
[C]Celsius & Farenheit Conversion Table
I kind of have this one worked out, somewhat. What I'm trying to do, is create a table using a for loop. The table will have Celsius from 0 to 100 and a table for Farenheit 32 to 212.
Here's what I got: Code:
/* This program prints out a conversion table for Celsuis to Farenheit (0 to 100) and Farenheit to Celsius (32 to 212). Written by: */ #include <stdio.h> #define Conversion_Factor (100.0 / 180.0) int main (void) { /* Local Definitions */ float x; float y; /* Statements */ printf(" Farenheit Conversion Table\n"); for ( x = 0; x <= 100; x++) { /* Centigrade to Farenheit */ printf("%.2f\t", (Conversion_Factor * x) + 32); } printf("\n"); return 0; } /* main */ /* Results */ Code:
Farenheit Conversion Table 32.00 32.56 33.11 33.67 34.22 34.78 35.33 35.89 36.44 37.00 37.56 38.11 38.67 39.22 39.78 40.33 40.89 41.44 42.00 42.56 43.11 43.67 44.22 44.78 45.33 45.89 46.44 47.00 47.56 48.11 48.67 49.22 49.78 50.33 50.89 51.44 52.00 52.56 53.11 53.67 54.22 54.78 55.33 55.89 56.44 57.00 57.56 58.11 58.67 59.22 59.78 60.33 60.89 61.44 62.00 62.56 63.11 63.67 64.22 64.78 65.33 65.89 66.44 67.00 67.56 68.11 68.67 69.22 69.78 70.33 70.89 71.44 72.00 72.56 73.11 73.67 74.22 74.78 75.33 75.89 76.44 77.00 77.56 78.11 78.67 79.22 79.78 80.33 80.89 81.44 82.00 82.56 83.11 83.67 84.22 84.78 85.33 85.89 86.44 87.00 87.56 Press any key to continue Code:
printf("Centigrade Conversion Table\n"); for( y = 32; y <= 212; y++) { /* Farenheit to Centigrade */ printf("%.2f\t", Conversion_Factor * (y - 32); } printf("\n"); |
12-12-2004, 02:11 PM | #2 (permalink) |
I am Winter Born
Location: Alexandria, VA
|
Code:
#include <stdio.h> #define CFRATIO (9.0/5.0) #define FCRATIO (5.0/9.0) int main (void) { /* Local Definitions */ int i; /* Statements */ printf("Celcius -> Farenheit Conversion Table\n"); for ( i = 0; i <= 100; i++) { /* Centigrade to Fahrenheit */ printf("%.2f\t", (CFRATIO * i) + 32); if( ( (i+1) % 10 ) == 0 ) { printf("\n"); } } printf("\nFahrenheit -> Celcius Conversion Table\n" ); for ( i = 32; i <= 212; i++) { /* Fahrenheit to Centigrade */ printf("%.2f\t", (i - 32) * FCRATIO ); if( ( (i+1) % 10 ) == 0 ) { printf("\n"); } } printf("\n"); return 0; } |
Tags |
ccelsius, conversion, farenheit, table |
|
|