这也没个介绍,让我查呀查呀,一看,原来是个这
程序代码:
#include<stdio.h> #include<math.h> float integral(float a, float b, int n, float(*fun)(float x)) { int i; float x, h, s; h = (b - a) / n; x = a; s = 0; for (i = 1; i <= n; i++) { x = x + h; s = s + (*fun)(x)*h; } return s; } float fsin(float x) { return sin(x); } float fcos(float x) { return cos(x); } float fexp(float x) { return exp(x); } int main() { float integral(float a, float b, int n, float(*fun)(float)); float fsin(float x); float fcos(float x); float fexp(float x); float a1 = 0, b1 = 1, a2 = -1, b2 = 1, a3 = 0, b3 = 2, n = 20; printf("f1=%5.2f\n", integral(a1, b1, n, fsin)); printf("f2=%5.2f\n", integral(a2, b2, n, fcos)); printf("f3=%5.2f\n", integral(a3, b3, n, fexp)); return 0; }