From 2d14ef6cc55b61d5e951d3edce864f0698b1b9a6 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Fri, 23 Oct 2015 23:49:09 +0200 Subject: [PATCH] Add remaining prog exercises of chapter 04 --- c_primer_plus/chapter04/07.c | 19 +++++++++++++++++++ c_primer_plus/chapter04/08.c | 23 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 c_primer_plus/chapter04/07.c create mode 100644 c_primer_plus/chapter04/08.c diff --git a/c_primer_plus/chapter04/07.c b/c_primer_plus/chapter04/07.c new file mode 100644 index 0000000..596de98 --- /dev/null +++ b/c_primer_plus/chapter04/07.c @@ -0,0 +1,19 @@ +#include +#include + + + +int main (void) { + + + float f_var = 1.0 / 3.0; + double d_var = 1.0 / 3.0; + + printf("float: %18.4f double: %18.4g\n", f_var, d_var); + printf("float: %18.12f double: %18.12g\n", f_var, d_var); + printf("float: %.16f double: %.16g\n", f_var, d_var); + printf("FLT_DIG: %16d DBL_DIG: %17d \n", FLT_DIG, DBL_DIG); + + return 0; + +} diff --git a/c_primer_plus/chapter04/08.c b/c_primer_plus/chapter04/08.c new file mode 100644 index 0000000..4163e64 --- /dev/null +++ b/c_primer_plus/chapter04/08.c @@ -0,0 +1,23 @@ +#include + + +#define LITERS_PER_GALLON 3.786 +#define KM_PER_MILE 1.609 + + +int main (void) { + + float miles; + float gallons; + + printf("Miles traveled: "); + scanf("%f", &miles); + printf("gasoline gallons: "); + scanf("%f", &gallons); + + printf("Miles per gallon: %.1f\n", miles / gallons); + printf("Liters per 100km: %.1f\n", (gallons * LITERS_PER_GALLON)/(miles * KM_PER_MILE)); + + return 0; + +}