{ Integ.pas by Richard J. Davies                                              }
{ from `Introductory Java for Scientists and Engineers'                       }
{ chapter: `Java from Basics'                                                 }
{ section: `Example - Integration'                                            }
{                                                                             }
{ This is a Pascal program to integrate 1/(1+x) between x=1 and x=2 by the    }
{ trapezium rule with 100 divisions. It is included for comparison with       }
{ the Java version `Integ.java'.                                              }

program Integ;
uses
  WinCrt;

var
  total, x, y : real;
  i : integer;

begin
  total := 0;

  { We are using the trapezium rule, so each end }
  { point has a weighting of one.                }

  total := total + 1 / (1 + 1.0);  { LH end, x = 1 }
  total := total + 1 / (1 + 2.0);  { RH end, x = 2 }

  { whilst each middle point has weight two. }
  
  for i := 1 to 99 do
  begin
    x := 1 + i/100.0;
    y := 1 / (x + 1);

    total := total + 2*y;
  end;

  { Finally, we multiply by half the step size }

  total := total * 0.005;

  Writeln(total);
end.

