Browse Source

Add remaining prog exercises of chapter 04

master
T. Meissner 9 years ago
parent
commit
2d14ef6cc5
2 changed files with 42 additions and 0 deletions
  1. +19
    -0
      c_primer_plus/chapter04/07.c
  2. +23
    -0
      c_primer_plus/chapter04/08.c

+ 19
- 0
c_primer_plus/chapter04/07.c View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <float.h>
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;
}

+ 23
- 0
c_primer_plus/chapter04/08.c View File

@ -0,0 +1,23 @@
#include <stdio.h>
#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;
}

Loading…
Cancel
Save