如题,谢谢

解决方案 »

  1.   

    type func=function(x:real):real;function y(x:real):real;
    begin
         y:=1/(1+x);
    end;function sin1(x:real):real;
    begin
         sin1:=sin(x);
    end;
    procedure integ(operation:func; a,b:real;var inte:real);
    const     n=100;
    var
       s,w:real;
       i:integer;begin
         w:=(b-a)/n;
         s:=(operation(a)+operation(b))/2;
         for i:=1 to n-1 do
         s:=s+operation(a+i*w);
         inte:=w*s;
    end;var a0,b0,inte0:real;begin
         writeln('Please input a and b:');
         readln(a0,b0);
         writeln('The following counts the integal of y=1/(1+x) from ');
             writeln(a0:10:2,' to ',b0:10:2,':');
         integ(y,a0,b0,inte0);
         writeln('Throught method we get inte0=',inte0:10:2);
         writeln('The following counts the integal of y=sin(x) from ',a0:10:2,' to ',b0:10:2,':');
         integ(sin1,a0,b0,inte0);
         writeln('Throught method we get inte0=',inte0:10:2);
         
    end.