#include<stdio.h>
#include<math.h>
float fexp(float x)
{return exp(x);
}
float Integral(float (*p)(float),float a,float b,int n)
{float x,h,sum,i;
x=a;
h=(a+b)/n;
sum=0;
for(i=0;i<n;i++)
{x=x+h;
sum=sum+(*p)(x)*h;
}
return sum;
}
float f(float x)
{float pfexp;
pfexp=fexp(x);
return (pfexp*(1-pfexp));
}
main()
{float x,y,integral,a,b,pf,(*p)(float);
int n;
printf("Enter \'n\'(Tt is used for controlling the definition of theintegral!):");
scanf("%d",&n);
a=0.1;
b=0.5;
p=f;
integral=Integral(p,a,b,n);
printf("The result is:%7.2f\n",integral);
}
这次应该差不多了!
不然我也就黔驴技穷了!
#include<math.h>
float fexp(float x)
{return exp(x);
}
float Integral(float (*p)(float),float a,float b,int n)
{float x,h,sum,i;
x=a;
h=(a+b)/n;
sum=0;
for(i=0;i<n;i++)
{x=x+h;
sum=sum+(*p)(x)*h;
}
return sum;
}
float f(float x)
{float pfexp;
pfexp=fexp(x);
return (pfexp*(1-pfexp));
}
main()
{float x,y,integral,a,b,pf,(*p)(float);
int n;
printf("Enter \'n\'(Tt is used for controlling the definition of theintegral!):");
scanf("%d",&n);
a=0.1;
b=0.5;
p=f;
integral=Integral(p,a,b,n);
printf("The result is:%7.2f\n",integral);
}
这次应该差不多了!
不然我也就黔驴技穷了!
[此贴子已经被作者于2006-11-11 15:49:04编辑过]