Skip to content
Snippets Groups Projects
Commit c255da4d authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Musterlösung 23.1.2020

parent c0fd3518
No related branches found
No related tags found
No related merge requests found
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment