program assignment2_3;

type points = array [0..3] of real;

var xcal, ycal:points;
    x, y:real;

procedure interp(xcal, ycal:points; x:real; var y:real);

var temp:real;
    i, j:integer;

begin

  y:=0;

  for i:=0 to 3 do begin

    temp:=ycal[i];

    for j:=1 to 3 do begin

      temp:=temp*(x-xcal[(i+j) mod 4])/(xcal[i]-xcal[(i+j) mod 4]);

    end;

    y:=y+temp;

  end;

end;

begin

  xcal[0]:=0;
  xcal[1]:=1;
  xcal[2]:=2;
  xcal[3]:=3;

  ycal[0]:=0;
  ycal[1]:=3;
  ycal[2]:=14;
  ycal[3]:=39;

  writeln('What value of x would you like to interpolate for?');
  readln(x);

  interp(xcal, ycal, x, y);

  writeln('(',x:1:3,', ',y:1:3,')');

  readln;

end.
