#include <stdio.h>
#include <stdlib.h>
#define LENGTH 3
int main(void) {
double *map(double (*)(double), const double *, int); // 映射函数
double pow2(double);
double * p = map(pow2, (double[LENGTH]){1.2, 2.8, 3.4}, LENGTH);
for (int i = 0; i < LENGTH; ++i) {
printf("%lf, ", p[i]);
}
puts("");
free(p);
p = NULL;
return 0;
}
double pow2(double num) { return num * num; }
double *map(double (*pf)(double), const double *p, int n) {
double *pd = malloc(n * sizeof(double));
for (int i = 0; i < n; i++) {
pd[i] = pf(p[i]);
}
return pd;
}