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
xTN@](7CL5ӆN!*Z * nRgl' cnk=Ǭf/l;i|y+KHqQc&\T e!4&'UI=QAd*Pڒ04\*2V~pJ%X K ɴTG#CN*`dd0nDR;T*5pz sx(?3"=84:g8k|?Xy;>t/w7[Z|vNG!!Dzۭ#ڊl.{^=Uj;|an^oy_e['B:!JW0V zĺAcn]%M6WŁv@ UFYZl/5%𪍁Mn}4nNg~Lbݛ]A|IԉͬvhECuku2 T~lw"ro* }h(ߕ &8}}STFO NH "Nt NuSK01q1ym<S z*L̖M'?XC%GRqgDxfQ ж~bVyF~.r8c3 11*gUs{m`M18dAaBtQErh.G,(iD@WITDqXWC :Te[ .pH%'B "^!?*󂖓@NGg[ 1.P

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;
}

#include<stdio.h>
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);
}