From b389a7e623bf3288296043b1ee1c868e55eb9fbe Mon Sep 17 00:00:00 2001 From: tmeissner Date: Tue, 20 Oct 2015 23:23:33 +0200 Subject: [PATCH] Add Makefile & last two exercises of chapter 03 --- c_primer_plus/chapter03/07.c | 17 +++++++++++++++++ c_primer_plus/chapter03/08.c | 24 ++++++++++++++++++++++++ c_primer_plus/chapter03/Makefile | 14 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 c_primer_plus/chapter03/07.c create mode 100644 c_primer_plus/chapter03/08.c create mode 100644 c_primer_plus/chapter03/Makefile diff --git a/c_primer_plus/chapter03/07.c b/c_primer_plus/chapter03/07.c new file mode 100644 index 0000000..05beff6 --- /dev/null +++ b/c_primer_plus/chapter03/07.c @@ -0,0 +1,17 @@ +#include + + +#define CM_PER_INCH 2.54 + + +int main (void) { + + float inches; + + printf("Enter your height in inches: "); + scanf("%f", &inches); + printf("Your height in cm is %.2f\n", inches * CM_PER_INCH); + + return 0; + +} diff --git a/c_primer_plus/chapter03/08.c b/c_primer_plus/chapter03/08.c new file mode 100644 index 0000000..938fe6e --- /dev/null +++ b/c_primer_plus/chapter03/08.c @@ -0,0 +1,24 @@ +#include + + + +int main (void) { + + float cups; + + printf("Give a volume in cups: "); + scanf("%f", &cups); + + float pints = cups / 2; + float ounces = cups * 8; + float tablespoons = ounces * 2; + float teaspoons = tablespoons * 3; + + printf("The given volume are %0.2f pints\n", pints); + printf("The given volume are %0.2f ounces\n", ounces); + printf("The given volume are %0.2f tablespoons\n", tablespoons); + printf("The given volume are %0.2f teaspoons\n", teaspoons); + + return 0; + +} diff --git a/c_primer_plus/chapter03/Makefile b/c_primer_plus/chapter03/Makefile new file mode 100644 index 0000000..4d59a80 --- /dev/null +++ b/c_primer_plus/chapter03/Makefile @@ -0,0 +1,14 @@ +SRC := $(shell ls *.c) + + +.PHONY: all +all: + + +%: %.c + gcc -Wall -Wextra $@.c -o $@ + + +.PHONY: clean +clean: + @rm -f ?? \ No newline at end of file