Created
July 18, 2010 10:23
-
-
Save Mon-Ouie/480295 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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