4_34.cpp
上传用户:zipjojo
上传日期:2009-07-20
资源大小:70k
文件大小:1k
- # include<stdio.h>
- # include<math.h>
- # include<iostream.h>
- double fx(double w);
- double integral(double s,double t,int m);
- void main()
- {
- int n;
- double a,b,I;
- printf("请输入积分区间(从a到b),并输入等分区间数n:n");
- cin>>a>>b>>n;
- I=integral(a,b,n);
- printf("I=%fn",I);
- }
- double fx(double w)
- {
- return (log(1.0+w)/(1.0+w*w));
- }
- double integral(double s,double t,int m)
- {
- double (*p)(double w);
- p=fx;
- double f=0.0,h,x,y1,y2,area;
- h=(t-s)/m;
- x=s;
- y1=(*p)(x);
- for(int i=1;i<=m;i++)
- {
- x+=h;
- y2=(*p)(x);
- area=(y1+y2)*h/2;
- y1=y2;
- f+=area;
- }
- return f;
- }