<P>是呀,我自已写了一个,但有一个错误不知道怎么改,各位大侠请赐教。<BR>#include<math.h><BR>#include<stdio.h><BR>//全局变量<BR>double a[100],b[100];<BR>double L,X;<BR>double R[100],U[100];<BR>int k=1;<BR>//要计算的函数<BR>double function(double x){<BR> double y=(x+1)*(x-2)*(x-2);<BR> return y;<BR>}<BR>//初始化区间<BR>void Initalize(){<BR> printf("Input the a[1] and b[1]:\n");<BR> scanf("%lf %lf",&a[1],&b[1]);<BR> if(a[1]>b[1]){<BR> printf("error,the a[1] must be small than the b[1],please input again.\n");<BR> exit(0);<BR>}<BR> printf("Input the L\n");<BR> scanf("%lf",&L);<BR> if(L<0){<BR> printf("error,the L must be biger than zero.\n");<BR> exit(0);<BR> }<BR>}<BR>//step 3<BR>void Step3(){<BR> a[k+1]=R[k];<BR> b[k+1]=b[k];<BR> R[k+1]=U[k];<BR> U[k+1]=a[k+1]+2/3*(b[k+1]-a[k+1]);<BR>}<BR>//step4<BR>void Step4(){<BR> a[k+1]=a[k];<BR> b[k+1]=U[k];<BR> U[k+1]=R[k];<BR> R[k+1]=a[k+1]+1/3*(b[k+1]-a[k+1]);<BR>}<BR>//处理过程<BR>void process(){<BR> R[1]=a[1]+1/3*(b[1]-a[1]);<BR> U[1]=a[1]+2/3*(b[1]-a[1]);<BR> while((b[k]-a[k])>=L){<BR> if(function(R[k])>function(U[k])){<BR> Step3();<BR> }<BR> else {<BR> Step4();<BR> }<BR> k=k+1;<BR> }<BR> printf("the min area is :[%lf %lf]\n",a[k],b[k]);<BR> double X=(a[k]+b[k])/2;<BR> printf("the min point is:%lf\n",X);<BR>}<BR>//主函数<BR>void main(){<BR> Initalize();<BR> process();<BR>}<BR>getch();</P> |