1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-11-10 00:30:35 +00:00

Don't bury magic numbers!

This commit is contained in:
Kris Lamoureux 2021-11-05 20:42:05 -04:00
parent f88aa3d25f
commit fe248c5a30
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
2 changed files with 10 additions and 2 deletions

View File

@ -1,11 +1,15 @@
#include <stdio.h> #include <stdio.h>
#define LOWER 0
#define UPPER 300
#define STEP 20
/* print Fahrenheit-Celsius table */ /* print Fahrenheit-Celsius table */
int main() int main()
{ {
int fahr; int fahr;
printf("Fahrenheit\tCelsius\n=======================\n"); printf("Fahrenheit\tCelsius\n=======================\n");
for (fahr = 300; fahr >= 0; fahr = fahr - 20) for (fahr = UPPER; fahr >= LOWER; fahr = fahr - STEP)
printf("%3d\t\t%7.1f\n", fahr, (5.0/9.0)*(fahr-32)); printf("%3d\t\t%7.1f\n", fahr, (5.0/9.0)*(fahr-32));
} }

View File

@ -1,11 +1,15 @@
#include <stdio.h> #include <stdio.h>
#define LOWER 0
#define UPPER 300
#define STEP 20
/* print Celsius-Fahrenheit table */ /* print Celsius-Fahrenheit table */
int main() int main()
{ {
int cels; int cels;
printf("Celsius\t\tFahrenheit\n==========================\n"); printf("Celsius\t\tFahrenheit\n==========================\n");
for (cels = 0; cels <= 300; cels = cels + 20) for (cels = LOWER; cels <= UPPER; cels = cels + STEP)
printf("%3d\t\t%10.0f\n", cels, (9.0/5.0)*cels+32); printf("%3d\t\t%10.0f\n", cels, (9.0/5.0)*cels+32);
} }