你这个不是函数指针啦。

授人以渔,不授人以鱼。
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
double Integral(double low, double high, double increase, double (*Func)(double));
double Func1(double x);
double Func2(double x);
double Func3(double x);
const double Increase = 0.0001;
int main(void)
{
printf_s("f(x) = x^3 +3x^2 - x + 4 在 (0,1)上的定积分 = %f\n", Integral(0.0, 1.0, Increase, Func1));
printf_s("f(x) = x * sqrt(1 + cos2x) 在 (0,1)上的定积分 = %f\n", Integral(0.0, 1.0, Increase, Func2));
printf_s("f(x) = 1 / (1 + x^2) 在 (0,1)上的定积分 = %f\n", Integral(0.0, 1.0, Increase, Func3));
_getch();
return EXIT_SUCCESS;
}
// 求任意函数的定积分
double Integral(double low, double high, double increase, double (*Func)(double))
{
double integral = 0.0;
for (double x = low; x <= high; x += increase)
{
integral += Func(x) * increase;
}
return integral;
}
// f(x) = x^3 + 3x^2 - x + 4
double Func1(double x)
{
return pow(x, 3) + 3 * pow(x, 2) - x + 4;
}
// f(x) = x * sqrt(1 + cos2x)
double Func2(double x)
{
return x * sqrt(1 + cos(2 * x));
}
// f(x) = 1 / (1 + x^2)
double Func3(double x)
{
return 1 / (1 + pow(x, 2));
}
