From 8e27e7e0b6a6a3c35a1b769281471211f4364de3 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 12 Apr 2016 10:26:24 -0400 Subject: [PATCH] ex7 --- lcthw-remnants-2/.gitignore | 1 + lcthw-remnants-2/ex7.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lcthw-remnants-2/ex7.c diff --git a/lcthw-remnants-2/.gitignore b/lcthw-remnants-2/.gitignore index 530a0f4..c6be593 100644 --- a/lcthw-remnants-2/.gitignore +++ b/lcthw-remnants-2/.gitignore @@ -3,3 +3,4 @@ ex3 ex4 ex5 ex6 +ex7 diff --git a/lcthw-remnants-2/ex7.c b/lcthw-remnants-2/ex7.c new file mode 100644 index 0000000..1d02d2b --- /dev/null +++ b/lcthw-remnants-2/ex7.c @@ -0,0 +1,30 @@ +#include + +int main(int argc, char *argv[]) +{ + int bugs = 100; + double bug_rate = 1.2; + + printf("You have %d bugs at the imaginary rate of %f.\n", + bugs, bug_rate); + + long universe_of_defects = 1L * 1024L * 1024L * 1024L; + printf("The entire universe has %ld bugs.\n", + universe_of_defects); + + double expected_bugs = bugs * bug_rate; + printf("You are expected to have %f bugs.\n", + expected_bugs); + + double part_of_universe = expected_bugs / universe_of_defects; + printf("That is only a %e portion of the universe.\n", + part_of_universe); + + // this makes no sense, just a demo of something weird + char nul_byte = '\0'; + int care_percentage = bugs * nul_byte; + printf("Which means you should care %d%%.\n", + care_percentage); + + return 0; +}