程序如下:编译老是出问题,改了几天了!急死我了!下星期要交的论文啊!谢谢各位大虾相救!!!! #include <stdio.h> #include <math.h> #include <malloc.h> #include <conio.h> double *fls(double x) { double *y; y=(double *)malloc(2*sizeof(double)); y[0]=-sqrt(1-x*x); y[1]=-y[0]; return y; } double f(double x,double y) { double result; result=exq(x*x+y*y); return result; } double *simps1(double x,double eps) { double *result,*y; int n=1,i,kflag=0; double h,e,t1,yy,t2,s,s0; result=(double *)malloc(3 *sizeof(double)); y=fls(x); h=0.5*(y[1]-y[0]); e=fabs(y[0])+fabs(y[1]); t1=h*(f(x,y[0])+f(x,y[1])); do { yy=y[0]-h; t2=0.5*t1; for(i=1;i<=n;i++) { yy=yy+2.0*h; t2=t2+h*f(x,yy); } s=(4.0*t2-t1)/3.0; n=n+n; if(n<8) {s0=s; t1=t2; h=0.5*h; } if(fabs(s-s0)<=eps*(fabs(s)+1.0)) break; s0=s; t1=t2; h=0.5*h; }while(e+h!=e); if(y[0]!=y[1]) kflag=kflag+1; result[0]=kflag; result[1]=n; result[2]=s; return(result); } double *simps2(double a,double b,double eps) { double *result,*m,x; int n2=1,n,n1,n3,ss1,ss2,sum,sum0,i,kflag=0,flag=0; double h,c,t1,t2; result=(double *)malloc(3*sizeof(double)); double h,d,s1,s2,t1,x,t2,g,eps,s,s0; c=fabs(a)+fabs(b); h=0.5*(b-a); m=simps1(a,eps); n1=m[1]; ss1=m[2]; m=simps1(b,eps); n3=m[1]; ss2=m[2]; n=n1+n3+2; t1=h*(ss2+ss1); do { x=a-h; t2=0.5*t1; for(i=1;i<=n2;i++) { x=x+2.0*h; m=simps1(x,eps); n=n+m[1]+1; t2=t2+h*m[2]; } sum=(4.0*t2-t1)/3.0; n2=n2+n2; if(n2<8) { sum0=sum; t1=t2; h=0.5; } if(fabs(sum-sum0)<=eps*(fabs(sum)+1.0)) { result[0]=kflag; result[1]=n; result[2]=sum; flag=1; break; } so=s; t1=t2; h=0.5*h; }while(c+h!=c); if(flag==1) kflag=kflag+1; result[0]=kflag; result[1]=n; result[2]=sum; return(result); } main() {double EPS=5.0e-5; double *result; result=simps2(0.0,1.0,EPS); printf("I=%f",result[2]);
}