LINUX.ORG.RU

История изменений

Исправление Legioner, (текущая версия) :

А в чём проблема?

#include <stdio.h>

typedef int (*reduce_function)(int x, int y);

int reduce(reduce_function f, int z, int *xs, int *xe)
{
    return xs == xe ? z : reduce(f, f(z, *xs), xs + 1, xe);
}

int r(int x, int y)
{
    return x * 2 + y;
}

int main()
{
    int xs[] = {1, 2, 3};
    int v = reduce(r, 4, xs, xs + 3);
    printf("%d\n", v);
    return 0;
}

Исходная версия Legioner, :

А в чём проблема?

[code=c] #include <stdio.h>

typedef int (*reduce_function)(int x, int y);

int reduce(reduce_function f, int z, int *xs, int *xe) { return xs == xe ? z : reduce(f, f(z, *xs), xs + 1, xe); }

int r(int x, int y) { return x * 2 + y; }

int main() { int xs[] = {1, 2, 3}; int v = reduce(r, 4, xs, xs + 3); printf(«%d\n», v); return 0; } [/code]