关于积分的问题
#include <math.h>#include <stdio.h>
#include <iostream.h>
void main()
{
float integral(float(*p)(float),float,float,int);
float a1,b1,c,(*p)(float);
float fsin(float);
int n=20;
printf("Input al,bl:");
cin>>a1>>b1;
p=fsin;
c=integral(p,a1,b1,n);
printf("The integral of sin(x) is:%f\n", c);
}
float integral(float(*p)(float),float a,float b,int n)
{
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+(*p)(x)*h;
}
return(s);
}
根据答案改变,不知道错在哪里???