int main (void) { float fahr, celsium; int lower, upper, step; /** lower limit of temperature table */ lower = 0; /** upper limit */ upper = 300; /** step size */ step = 20; fahr = lower; printf("fahrenheit\tcelsium\n"); printf("__________\t_______\n"); while (fahr <= upper) { // celsium = (5.0/9.0) * (fahr - 32.0); celsium = fahr2cel (fahr); printf("%3.0f\t\t%6.1f\n", fahr, celsium); fahr = fahr + step; } return 0; }
int main(int argc, char const *argv[]) { float celsius; for (int fahrenheit = 0; fahrenheit <= 300; fahrenheit+=20) { if (fahrenheit == 0) printf("Fahrenheit\tCelsius\n"); celsius = fahr2cel(fahrenheit); printf("%i\t\t%f\n",fahrenheit,celsius); } return 0; }
/* Print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300. * This is the solution for K&R 1-15.*/ main() { float fahr; printf("Fahrenheit-Celsius Table\n"); /* print a head above the table*/ printf("------------------------\n"); printf("%4s\t%6s\n","FAHR","CELS"); printf("------------------------\n"); fahr = LOWER; while(fahr <= UPPER) { printf("%4.0f\t%6.1f\n", fahr, fahr2cel(fahr)); fahr = fahr + STEP; } }