From c255da4dd56398b3a641abfdf659d7da19bd5373 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter.gerwinski@hs-bochum.de> Date: Thu, 23 Jan 2020 13:56:43 +0100 Subject: [PATCH] =?UTF-8?q?Musterl=C3=B6sung=2023.1.2020?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 20200123/loesung-2.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 20200123/loesung-2.c diff --git a/20200123/loesung-2.c b/20200123/loesung-2.c new file mode 100644 index 0000000..7a277e7 --- /dev/null +++ b/20200123/loesung-2.c @@ -0,0 +1,30 @@ +#include <stdio.h> + +void foreach (int *a, void (*fun) (int x)) +{ + for (int *p = a; *p >= 0; p++) + fun (*p); +} + +void even_or_odd (int x) +{ + if (x % 2) + printf ("%d ist ungerade.\n", x); + else + printf ("%d ist gerade.\n", x); +} + +int sum = 0; + +void add_up (int x) +{ + sum += x; +} + +int main (void) +{ + int numbers[] = { 12, 17, 32, 1, 3, 16, 19, 18, -1 }; + foreach (numbers, add_up); + printf ("Summe: %d\n", sum); + return 0; +} -- GitLab