C语言,有关求定积分#define N 100#includedouble *f(double x){\x09double a=x*x+x;\x09double *p=&a;\x09return p;}double intergral(double a,double b,double(*f)(double)){\x09double h=(b-a)/N,S=0;\x09int i;\x09for(i=0;i
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/29 23:50:02
C语言,有关求定积分#define N 100#includedouble *f(double x){\x09double a=x*x+x;\x09double *p=&a;\x09return p;}double intergral(double a,double b,double(*f)(double)){\x09double h=(b-a)/N,S=0;\x09int i;\x09for(i=0;i
C语言,有关求定积分
#define N 100
#include
double *f(double x)
{
\x09double a=x*x+x;
\x09double *p=&a;
\x09return p;
}
double intergral(double a,double b,double(*f)(double))
{
\x09double h=(b-a)/N,S=0;
\x09int i;
\x09for(i=0;i
C语言,有关求定积分#define N 100#includedouble *f(double x){\x09double a=x*x+x;\x09double *p=&a;\x09return p;}double intergral(double a,double b,double(*f)(double)){\x09double h=(b-a)/N,S=0;\x09int i;\x09for(i=0;i
要学会看错误提示
double intergral(double a,double b,double(*f)(double))
这个函数的第三个参数你传错了
第三个参数是一个函数的指针,这个函数的返回值类型是double参数类型是double
而你传的f函数,他的返回值类型是double *不是double
所以报你第三个参数传错了,
实际上就是你的f函数写错了,改下就行了:
double f(double x)
{
double a=x*x+x;
return a;
}
double f(double x)
{
double a=x*x+x;
return a;
}
double intergral(double a,double b,double(*f)(double))
{
double h=(b-a)/N,S=0;
int i;
for(i=0;i<N;i++)
S=S+f(a+i*h)+f(a+(i+1)*h);
S=S*h/2;
return S;
}
void main()
{
double sum;
sum=intergral(1,3,f);
printf("%lf",sum);
}