From 3d82fabc963204ae5e52d8a56098ad41a5cae055 Mon Sep 17 00:00:00 2001 From: tmeissner Date: Fri, 23 Oct 2015 23:26:10 +0200 Subject: [PATCH] Add more prog exercices of chapter 04 --- c_primer_plus/chapter04/03.c | 17 +++++++++++++++++ c_primer_plus/chapter04/04.c | 19 +++++++++++++++++++ c_primer_plus/chapter04/05.c | 20 ++++++++++++++++++++ c_primer_plus/chapter04/06.c | 22 ++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 c_primer_plus/chapter04/03.c create mode 100644 c_primer_plus/chapter04/04.c create mode 100644 c_primer_plus/chapter04/05.c create mode 100644 c_primer_plus/chapter04/06.c diff --git a/c_primer_plus/chapter04/03.c b/c_primer_plus/chapter04/03.c new file mode 100644 index 0000000..72c388c --- /dev/null +++ b/c_primer_plus/chapter04/03.c @@ -0,0 +1,17 @@ +#include +#include + + + +int main (void) { + + float number; + + printf("Give a float number: "); + scanf("%g", &number); + printf("The input is %.1f or %.1e\n", number, number); + printf("The input is %+.3f or %.3e\n", number, number); + + return 0; + +} diff --git a/c_primer_plus/chapter04/04.c b/c_primer_plus/chapter04/04.c new file mode 100644 index 0000000..7e085c9 --- /dev/null +++ b/c_primer_plus/chapter04/04.c @@ -0,0 +1,19 @@ +#include +#include + + + +int main (void) { + + float height; + char name[21]; + + printf("Give your heigth in cm: "); + scanf("%f", &height); + printf("Give your name: "); + scanf("%20s", name); + printf("%s, you are %.3f m tall\n", name, height/100); + + return 0; + +} diff --git a/c_primer_plus/chapter04/05.c b/c_primer_plus/chapter04/05.c new file mode 100644 index 0000000..94f4e16 --- /dev/null +++ b/c_primer_plus/chapter04/05.c @@ -0,0 +1,20 @@ +#include +#include + + + +int main (void) { + + float speed; + float size; + + printf("Give download speed in Mbit/s: "); + scanf("%f", &speed); + printf("Give file size in Mbytes: "); + scanf("%f", &size); + printf("At %.2f megaits per second, a file of %.2f megabytes\n", speed, size); + printf("downloads in %.2f seconds\n", size*8/speed); + + return 0; + +} diff --git a/c_primer_plus/chapter04/06.c b/c_primer_plus/chapter04/06.c new file mode 100644 index 0000000..59e2c6b --- /dev/null +++ b/c_primer_plus/chapter04/06.c @@ -0,0 +1,22 @@ +#include +#include + + + +int main (void) { + + char first_name[21]; + char last_name[21]; + + printf("Give your first name: "); + scanf("%20s", first_name); + printf("Give your last name: "); + scanf("%20s", last_name); + printf("%s %s\n", first_name, last_name); + printf("%*lu %*lu\n", (int)strlen(first_name), strlen(first_name), (int)strlen(last_name), strlen(last_name)); + printf("%s %s\n", first_name, last_name); + printf("%-*lu %-*lu\n", (int)strlen(first_name), strlen(first_name), (int)strlen(last_name), strlen(last_name)); + + return 0; + +}