Skip to content

Commit 485a370

Browse files
committed
added c implementation
0 parents  commit 485a370

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

fp.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
3+
#define ARRSIZ 5
4+
5+
int increment(int n) {
6+
return n + 1;
7+
}
8+
9+
void my_objective(int *arr, const int SIZE, int (*f)(int)) {
10+
for (int i = 0; i < SIZE; ++i)
11+
arr[i] = f(arr[i]);
12+
}
13+
14+
int main() {
15+
int arr[ARRSIZ] = {0, 1, 2, 3, 4};
16+
my_objective(arr, ARRSIZ, increment);
17+
18+
for (int i = 0; i < ARRSIZ; ++i)
19+
printf("%d ", arr[i]);
20+
putchar('\0');
21+
}

0 commit comments

Comments
 (0)