22 lines
578 B
C
22 lines
578 B
C
#include <stdio.h>
|
|
int increment(int x)
|
|
{
|
|
return x + 1;
|
|
}
|
|
|
|
//TODO: implement a function map
|
|
// It applys the function to all members of the array.
|
|
// The first argument is always a pointer to the first argument in a array
|
|
// The second is its length and the third is a function that takes
|
|
// an integer and returns one.
|
|
// Each element in the array is replaced with the fucntions result
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
int nums[7] = {1, 2, 3, 4, 5, 6, 7};
|
|
map(nums, 7, &increment);
|
|
for (int i = 0; i < 7; i++) {
|
|
printf("%d,", nums[i]);
|
|
}
|
|
}
|