first draft of ex7.c
This commit is contained in:
parent
cd54bb1c46
commit
5328793953
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ ex3
|
||||
ex4
|
||||
ex5
|
||||
ex6
|
||||
ex7
|
||||
|
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
CFLAGS=-Wall -g
|
||||
|
||||
EXERCISES = ex1 ex3 ex4 ex5 ex6
|
||||
EXERCISES = ex1 ex3 ex4 ex5 ex6 ex7
|
||||
|
||||
|
||||
all: $(EXERCISES)
|
||||
|
30
ex7.c
Normal file
30
ex7.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user