Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created July 18, 2010 10:23
Show Gist options
  • Select an option

  • Save Mon-Ouie/480295 to your computer and use it in GitHub Desktop.

Select an option

Save Mon-Ouie/480295 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int inject_array(int *array, int size, int init,
int (^block)(int sum, int value)) {
for (int i = 0; i < size; i++)
init = block(init, array[i]);
return init;
}
int main(int argc, char **argv) {
int array[] = {
30, 60, 17, 120, 42, 25, 32, 47,
93, 75, 88, 230, 1270, 300, 400,
224, 440, 89, 330, 1, -100, 5052
};
int tab_size = sizeof(array) / sizeof(int);
int prod = inject_array(array, 5, 1, ^(int res, int val) {
return res * val;
});
printf("%d\n", prod);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment