From 5328793953201282d4e0258b8cfd819e28fd2a17 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Mon, 5 Sep 2011 20:50:39 -0400 Subject: [PATCH] first draft of ex7.c --- .gitignore | 1 + Makefile | 2 +- ex7.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ex7.c diff --git a/.gitignore b/.gitignore index 530a0f4..c6be593 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ ex3 ex4 ex5 ex6 +ex7 diff --git a/Makefile b/Makefile index a1a4945..f910ecc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CFLAGS=-Wall -g -EXERCISES = ex1 ex3 ex4 ex5 ex6 +EXERCISES = ex1 ex3 ex4 ex5 ex6 ex7 all: $(EXERCISES) diff --git a/ex7.c b/ex7.c new file mode 100644 index 0000000..6f3ef30 --- /dev/null +++ b/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 imaginary rate of %f.\n", + bugs, bug_rate); + + long universe_of_defects = 1 * 1024 * 1024 * 1024; + 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); + + + char nul_byte = '\0'; + int care_percentage = bugs * nul_byte; + printf("Which means you should care %d%%.\n", + care_percentage); + + return 0; +}