diff --git a/20211011/loesung-2-1a.c b/20211011/loesung-2-1a.c new file mode 100644 index 0000000000000000000000000000000000000000..8acad25cdce91f7f1dec5e2d8607a08f709cff2a --- /dev/null +++ b/20211011/loesung-2-1a.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int main (void) +{ + int a = 1; + int b = 7; + while (a <= 10) + { + printf ("%*d * %d = %*d\n", a, 2, b, a * b, 2); + a++; + } + return 0; +} diff --git a/20211011/loesung-2-1b.c b/20211011/loesung-2-1b.c new file mode 100644 index 0000000000000000000000000000000000000000..b739818db5ea8ecb13a18a1700bce9d9d4f85140 --- /dev/null +++ b/20211011/loesung-2-1b.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int main (void) +{ + int a = 1; + int b = 7; + while (a <= 10) + { + printf ("%*d * %d = %*d\n", 2, a, b, 2, a * b); + a++; + } + return 0; +} diff --git a/20211011/loesung-2-1c.c b/20211011/loesung-2-1c.c new file mode 100644 index 0000000000000000000000000000000000000000..f09dc57abf6efa82ab7918590126e721e1c7dd4d --- /dev/null +++ b/20211011/loesung-2-1c.c @@ -0,0 +1,16 @@ +#include <stdio.h> + +int main (void) +{ + int a = 1; + int b = 7; + char format[42]; + sprintf (format, "%%%dd * %%d = %%%dd\n", 2, 2); + printf ("format = %s\n", format); + while (a <= 10) + { + printf (format, a, b, a * b); + a++; + } + return 0; +} diff --git a/20211011/loesung-2-1d.c b/20211011/loesung-2-1d.c new file mode 100644 index 0000000000000000000000000000000000000000..8d4aa51b4ad32fd32bb2a62e31255f089bd3991e --- /dev/null +++ b/20211011/loesung-2-1d.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +int main (void) +{ + int a = 1; + int b = 7; + char format[42]; + snprintf (format, 42, "%%%dd * %%d = %%%dd\n", 2, 2); + format[41] = 0; + printf ("format = %s\n", format); + while (a <= 10) + { + printf (format, a, b, a * b); + a++; + } + return 0; +} diff --git a/20211011/loesung-3-6a.c b/20211011/loesung-3-6a.c new file mode 100644 index 0000000000000000000000000000000000000000..685ba9744a1fe3104459a75c9f534887b8ad4cd9 --- /dev/null +++ b/20211011/loesung-3-6a.c @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint128_t f0 = 0; + uint128_t f1 = 1; + for (int i = 0; i < 100; i++) + { + printf ("f[%d] = %lu\n", i, f0); + uint128_t f2 = f0 + f1; + f0 = f1; + f1 = f2; + } + return 0; +} diff --git a/20211018/arrays-1.c b/20211018/arrays-1.c new file mode 100644 index 0000000000000000000000000000000000000000..35cf856c63942234116544ac721ff0a47d797b09 --- /dev/null +++ b/20211018/arrays-1.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + int *p = prime; + for (int i = 0; i < 5; i++) + printf ("%d\n", *(p + i)); + return 0; +} diff --git a/20211018/arrays-2.c b/20211018/arrays-2.c new file mode 100644 index 0000000000000000000000000000000000000000..d206e6c3296fe7f7e48febd10893a5be65fca67a --- /dev/null +++ b/20211018/arrays-2.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + int *p = prime; + for (int i = 0; i < 5; i++) + printf ("%d\n", p[i]); + return 0; +} diff --git a/20211018/arrays-3.c b/20211018/arrays-3.c new file mode 100644 index 0000000000000000000000000000000000000000..83a03a4fe9425d684db38f0219cd9e9e19b405ba --- /dev/null +++ b/20211018/arrays-3.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + for (int i = 0; i < 5; i++) + printf ("%d\n", prime[i]); + return 0; +} diff --git a/20211018/arrays-4.c b/20211018/arrays-4.c new file mode 100644 index 0000000000000000000000000000000000000000..2015ffc6cd5057daaa755294ab4af602559eefa4 --- /dev/null +++ b/20211018/arrays-4.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int prime[5] = { 2, 3, 5, 7, 11 }; + for (int *p = prime; p < prime + 5; p++) + printf ("%d\n", *p); + return 0; +} diff --git a/20211018/arrays-5.c b/20211018/arrays-5.c new file mode 100644 index 0000000000000000000000000000000000000000..4d8164f19edc0e1fbfb3e5439f5c774e885d587b --- /dev/null +++ b/20211018/arrays-5.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int prime[5] = { 2, 3, 5, 7, 11, 0 }; + for (int *p = prime; *p; p++) + printf ("%d\n", *p); + return 0; +} diff --git a/20211018/arrays-6.c b/20211018/arrays-6.c new file mode 100644 index 0000000000000000000000000000000000000000..6e19ec4ef5e5b81e940168a4a4e6b3026a4f4375 --- /dev/null +++ b/20211018/arrays-6.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int prime[] = { 2, 3, 5, 7, 11, 0 }; + for (int *p = prime; *p; p++) + printf ("%d\n", *p); + return 0; +} diff --git a/20211018/break-4.c b/20211018/break-4.c new file mode 100644 index 0000000000000000000000000000000000000000..d220df63a91d22b12109e7968c7ac5d943b6686c --- /dev/null +++ b/20211018/break-4.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + return 1; +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year)) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/break-5.c b/20211018/break-5.c new file mode 100644 index 0000000000000000000000000000000000000000..193e6d5885211eac87b21d761d824ea5d5b4a9f5 --- /dev/null +++ b/20211018/break-5.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + return 0; +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year)) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/break-6.c b/20211018/break-6.c new file mode 100644 index 0000000000000000000000000000000000000000..1a8851e81cf16e5f78fcf9b4231e9749e6aad394 --- /dev/null +++ b/20211018/break-6.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + return 0; +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year) && year < 2100) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/break-7.c b/20211018/break-7.c new file mode 100644 index 0000000000000000000000000000000000000000..5acb21a56a0e02fdd436eb9a639788c844ad0cec --- /dev/null +++ b/20211018/break-7.c @@ -0,0 +1,26 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + if (year % 4 == 0) + { + if (year % 100 == 0) + { + if (year % 400 == 0) + return 1; + return 0; + } + return 1; + } +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year) && year < 2100) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/break-8.c b/20211018/break-8.c new file mode 100644 index 0000000000000000000000000000000000000000..6f5a540ebbdca11546eec869507987b9fb2d2a42 --- /dev/null +++ b/20211018/break-8.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + if (year % 4 == 0) + { + if (year % 100 == 0) + { + if (year % 400 == 0) + return 1; + return 0; + } + return 1; + } + return 0; +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year) && year < 2100) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/break-9.c b/20211018/break-9.c new file mode 100644 index 0000000000000000000000000000000000000000..878e0e01d062e50ff1326ec53d6f643d9c37b14e --- /dev/null +++ b/20211018/break-9.c @@ -0,0 +1,30 @@ +#include <stdio.h> + +/* Aufgabe: Suche das nächste Schaltjahr ab 2021. */ + +int is_leap_year (int year) +{ + if (year % 4 == 0) + { + if (year % 100 == 0) + { + if (year % 400 == 0) + return 1; + else + return 0; + } + else + return 1; + } + else + return 0; +} + +int main (void) +{ + int year = 2021; + while (!is_leap_year (year) && year < 2100) + year++; + printf ("Nächtgelegenes Schaltjahr: %d\n", year); + return 0; +} diff --git a/20211018/functions-1.c b/20211018/functions-1.c new file mode 100644 index 0000000000000000000000000000000000000000..b2db5145e720b39de50d37e98365b02f1bb25ca2 --- /dev/null +++ b/20211018/functions-1.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +void hello (void) +{ + printf ("Hello, world!\n"); +} + +int main (void) +{ + hello (); + return 0; +} diff --git a/20211018/functions-2.c b/20211018/functions-2.c new file mode 100644 index 0000000000000000000000000000000000000000..6d45a105f93558214757d623516098f7ffcb0de6 --- /dev/null +++ b/20211018/functions-2.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main (void) +{ + hello (); + return 0; +} + +void hello (void) +{ + printf ("Hello, world!\n"); +} diff --git a/20211018/functions-3.c b/20211018/functions-3.c new file mode 100644 index 0000000000000000000000000000000000000000..78ab747119dcb052254a670aa91955ab1e2079cc --- /dev/null +++ b/20211018/functions-3.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int main (void) +{ + int foo = hello (); + printf ("foo = %d\n", foo); + return 0; +} + +void hello (void) +{ + printf ("Hello, world!\n"); +} diff --git a/20211018/functions-4.c b/20211018/functions-4.c new file mode 100644 index 0000000000000000000000000000000000000000..c534cebceab4c38f8efa78e0a7dc0061fc4cb5e0 --- /dev/null +++ b/20211018/functions-4.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +void hello (void); + +int main (void) +{ + int foo = hello (); + printf ("foo = %d\n", foo); + return 0; +} + +void hello (void) +{ + printf ("Hello, world!\n"); +} diff --git a/20211018/functions-5.c b/20211018/functions-5.c new file mode 100644 index 0000000000000000000000000000000000000000..b387d663f4ccac0865a36ee6479f508bc0cc3295 --- /dev/null +++ b/20211018/functions-5.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +void hello (void); + +int main (void) +{ + hello (); + return 0; +} + +void hello (void) +{ + printf ("Hello, world!\n"); +} diff --git a/20211018/hp-20211018.pdf b/20211018/hp-20211018.pdf index 7f8bd320a3bbfd38ef25c6f20cbf1c361ce827cb..16a1db2fce34e872edc193ddb26025ebb148a1a3 100644 Binary files a/20211018/hp-20211018.pdf and b/20211018/hp-20211018.pdf differ diff --git a/20211018/hp-20211018.tex b/20211018/hp-20211018.tex index 849e726fed3ec639e7ff328d0bed6c293c1eee32..240819a3dc630b25e7937788255c1be853a5c374 100644 --- a/20211018/hp-20211018.tex +++ b/20211018/hp-20211018.tex @@ -964,6 +964,7 @@ \vspace{-\medskipamount} \begin{lstlisting}[gobble=8] + char ch = 'M'; if (ch >= 'A' && ch <= 'Z') ... \end{lstlisting} diff --git a/20211018/init-1.c b/20211018/init-1.c new file mode 100644 index 0000000000000000000000000000000000000000..b93ac83d89f7c25f0c8c9dc7cca7bcbb17218b2d --- /dev/null +++ b/20211018/init-1.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + int a = b = 3; + printf ("a = %d, b = %d\n", a, b); + return 0; +} diff --git a/20211018/init-2.c b/20211018/init-2.c new file mode 100644 index 0000000000000000000000000000000000000000..e5a2d48997750f27e47468d6b9d44f8ff307ee6f --- /dev/null +++ b/20211018/init-2.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + int a = int b = 3; + printf ("a = %d, b = %d\n", a, b); + return 0; +} diff --git a/20211018/init-3.c b/20211018/init-3.c new file mode 100644 index 0000000000000000000000000000000000000000..6ac2ef51d8f2ee27a222948102a32999f0acb23b --- /dev/null +++ b/20211018/init-3.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int b = 7; + int a = b = 3; + printf ("a = %d, b = %d\n", a, b); + return 0; +} diff --git a/20211018/init-4.c b/20211018/init-4.c new file mode 100644 index 0000000000000000000000000000000000000000..76f290ee4359ecba4bc5974483a0b5b44d4dc084 --- /dev/null +++ b/20211018/init-4.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + int b = 7; + int c = 13; + int a = b = c = 3; + printf ("a = %d, b = %d, c = %d\n", a, b, c); + return 0; +} diff --git a/20211018/strings-1.c b/20211018/strings-1.c new file mode 100644 index 0000000000000000000000000000000000000000..81bc3cda8affb6268786ac989dd2907d9a84783a --- /dev/null +++ b/20211018/strings-1.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%d", *p); + return 0; +} diff --git a/20211018/strings-2.c b/20211018/strings-2.c new file mode 100644 index 0000000000000000000000000000000000000000..4df32974a15ef2752512cc8b9889381b5a0917cd --- /dev/null +++ b/20211018/strings-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%c", *p); + return 0; +} diff --git a/20211018/strings-3.c b/20211018/strings-3.c new file mode 100644 index 0000000000000000000000000000000000000000..0e62e1e346091fab3da99c27973f54552eca2b5e --- /dev/null +++ b/20211018/strings-3.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%x", *p); + return 0; +} diff --git a/20211018/strings-4.c b/20211018/strings-4.c new file mode 100644 index 0000000000000000000000000000000000000000..ca99a886dc567e2ec28391d6284697298f996fd9 --- /dev/null +++ b/20211018/strings-4.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%02x", *p); + return 0; +} diff --git a/20211018/strings-5.c b/20211018/strings-5.c new file mode 100644 index 0000000000000000000000000000000000000000..12f486759dba62e999237775165da478d41dd3e6 --- /dev/null +++ b/20211018/strings-5.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 72, 101, 108, 108, 111, 0 }; + for (char *p = hello; *p; p++) + printf ("%02x", *p); + return 0; +} diff --git a/20211018/strings-6.c b/20211018/strings-6.c new file mode 100644 index 0000000000000000000000000000000000000000..d77f7e762d4d25a4facebfbfbeb6aeb9abade0d8 --- /dev/null +++ b/20211018/strings-6.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 72, 101, 108, 108, 111, 10, 0 }; + for (char *p = hello; *p; p++) + printf ("%c", *p); + return 0; +} diff --git a/20211018/strings-7.c b/20211018/strings-7.c new file mode 100644 index 0000000000000000000000000000000000000000..76edbc52b5ffccd44d3451b199a93d23d740f6b5 --- /dev/null +++ b/20211018/strings-7.c @@ -0,0 +1,6 @@ +#include <stdio.h> + +int main (void) +{ + printf ("2 hoch 6 = %d\n", '@'); +} diff --git a/20211018/structs-1.c b/20211018/structs-1.c new file mode 100644 index 0000000000000000000000000000000000000000..b83293df1ffb733d81170ec4aa00d890547cd644 --- /dev/null +++ b/20211018/structs-1.c @@ -0,0 +1,15 @@ +#include <stdio.h> + +typedef struct +{ + char day, month; + int year; +} +date; + +int main (void) +{ + date today = { 18, 10, 2021 }; + printf ("%d.%d.%d\n", today.day, today.month, today.year); + return 0; +} diff --git a/20211018/structs-2.c b/20211018/structs-2.c new file mode 100644 index 0000000000000000000000000000000000000000..1a8ba6ad69333562c7aadc282d57e37903f07f56 --- /dev/null +++ b/20211018/structs-2.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +typedef struct +{ + char day, month; + int year; +} +date; + +void set_date (date *d) +{ + (*d).day = 18; + (*d).month = 10; + (*d).year = 2021; +} + +int main (void) +{ + date today; + set_date (&today); + printf ("%d.%d.%d\n", today.day, today.month, today.year); + return 0; +} diff --git a/20211018/structs-3.c b/20211018/structs-3.c new file mode 100644 index 0000000000000000000000000000000000000000..1c051463ac6f958add35ea6096e86d93c09dcbf3 --- /dev/null +++ b/20211018/structs-3.c @@ -0,0 +1,5 @@ +#include <stdio.h> +typedef struct { char day, month; int year; } date; void set_date (date *d) { +(*d).day = 18; (*d).month = 10; (*d).year = 2021; } int main (void) { date +today; set_date (&today); printf ("%d.%d.%d\n", today.day, today.month, +today.year); return 0; } diff --git a/20211018/structs-4.c b/20211018/structs-4.c new file mode 100644 index 0000000000000000000000000000000000000000..5d41fe592b6838e3cb940f53689b3bc478437a14 --- /dev/null +++ b/20211018/structs-4.c @@ -0,0 +1,27 @@ +#include <stdio.h> + +typedef struct +{ + char day, month; + int year; +} date; + +void set_date (date *d) +{ + (*d).day = 18; + (*d).month = 10; + (*d).year = 2021; +} + +void print_date (date *d) +{ + printf ("%d.%d.%d\n", (*d).day, (*d).month, (*d).year); +} + +int main (void) +{ + date today; + set_date (&today); + print_date (&today); + return 0; +} diff --git a/20211018/structs-5.c b/20211018/structs-5.c new file mode 100644 index 0000000000000000000000000000000000000000..1cdf06f81a33b1296b15f64dc1865f8f3082ca12 --- /dev/null +++ b/20211018/structs-5.c @@ -0,0 +1,28 @@ +#include <stdio.h> + +typedef struct +{ + char day, month; + int year; +} +date; + +void set_date (date *d) +{ + d->day = 18; + d->month = 10; + d->year = 2021; +} + +void print_date (date *d) +{ + printf ("%d.%d.%d\n", d->day, d->month, d->year); +} + +int main (void) +{ + date today; + set_date (&today); + print_date (&today); + return 0; +}