diff --git a/c_primer_plus/chapter03/04.c b/c_primer_plus/chapter03/04.c index 403089a..8e11d92 100644 --- a/c_primer_plus/chapter03/04.c +++ b/c_primer_plus/chapter03/04.c @@ -8,9 +8,9 @@ int main (void) { printf("Enter a floating-point value: "); scanf("%f", &a); - printf("fixed-point notation: %f\n", a); - printf("exponential notation: %e\n", a); - printf("p notation: %a\n", a); + printf("fixed-point notation: %.2f\n", a); + printf("exponential notation: %.2e\n", a); + printf("p notation: %.2a\n", a); return 0; diff --git a/c_primer_plus/chapter03/05.c b/c_primer_plus/chapter03/05.c index 77b1d47..31e10f1 100644 --- a/c_primer_plus/chapter03/05.c +++ b/c_primer_plus/chapter03/05.c @@ -2,6 +2,9 @@ #include +#define SEC_PER_YEAR 3.156e7 + + int main (void) { @@ -10,13 +13,12 @@ int main (void) { printf("Enter your age: "); scanf("%u", &age); - if ((unsigned int)(UINT_MAX / 3.156e7) < age) { + if ((unsigned int)(UINT_MAX / SEC_PER_YEAR) < age) { printf("Integer overflow\n"); return 1; } else { - printf("You are %u seconds old\n", (unsigned int)(age * 3.156e7)); + printf("You are %u seconds old\n", (unsigned int)(age * SEC_PER_YEAR)); + return 0; } - return 0; - } diff --git a/c_primer_plus/chapter03/06.c b/c_primer_plus/chapter03/06.c index 80ebb0b..1350a83 100644 --- a/c_primer_plus/chapter03/06.c +++ b/c_primer_plus/chapter03/06.c @@ -1,6 +1,9 @@ #include +#define MOL_MASS 3.0e-23 +#define WATER_QUART_GRAM 950.0 + int main (void) { @@ -8,7 +11,7 @@ int main (void) { printf("Enter a amount of water, in quarts: "); scanf("%f", &quarts); - printf("Number of molecules: %e\n", quarts * 950.0 / 3.0e-23); + printf("Number of molecules: %.2e\n", quarts * WATER_QUART_GRAM / MOL_MASS); return 0;