Interpolation Points: The values you're using for interpolation (100!, 200!, 300!, 400!) are extremely large. Make sure the Lagrange polynomial is being computed with correct precision and that you handle very large numbers properly in your calculations.

Lagrange Polynomial Calculation: Double-check the polynomial formula and make sure the indices and arithmetic operations are correctly implemented. Small mistakes in the formula can lead to large discrepancies in the results.

Testing and Debugging: You might want to test with smaller, more manageable numbers to ensure that your polynomial interpolation is working as expected before scaling up to large factorials.

]]>If I understand right here are not links allowed?!?! So if you want to learn more about Lagrange Polynomial, then use Google...and same about factorial function.

I've been staring at my code for hours, looking for errors in it, but I can't find any. The Lagrange polynomial produces nonsense values. Could someone help? I would be more than grateful if someone could find a error in my code.

Known values are:

f(100)=100!

f(200)=200!

f(300)=300!

f(400)=400!

```
program FactorialAndLagrange;
uses math;
var f: array [1..2,0..3] of Extended;
x0,x1,x2,x3,y0,y1,y2,y3,x,Pol:Extended;
ind:Integer;
function factorial(m: Extended):Extended ; //counts m!
var i,result: Extended ;
begin
if m=0 then result:=1 else
begin
result:=1;
i:=1;
while i<=m do
begin
result:=result*i;
i:=i+1;
end;
end;
factorial:=result;
end;
begin
f[1,0]:=100;
f[1,1]:=200;
f[1,2]:=300;
f[1,3]:=400;
ind:=0;
while ind<=3 do
begin
f[2,ind]:=factorial(f[1,ind]);
writeln(f[1,ind],' ',f[2,ind]);
ind:=ind+1;
end;
x0:=f[1,0];
x1:=f[1,1];
x2:=f[1,2];
x3:=f[1,3];
y0:=f[2,0];
y1:=f[2,1];
y2:=f[2,2];
y3:=f[2,3];
x:=0;
while x<=1000 do
begin
Pol:=0;
Pol:=Pol+(((x-x1)*(x-x2)*(x-x3))/((x0-x1)*(x0-x2)*(x0-x3)))*y0;
Pol:=Pol+(((x-x0)*(x-x2)*(x-x3))/((x1-x0)*(x1-x2)*(x1-x3)))*y1;
Pol:=Pol+(((x-x0)*(x-x1)*(x-x3))/((x2-x0)*(x2-x1)*(x2-x3)))*y2;
Pol:=Pol+(((x-x0)*(x-x1)*(x-x2))/((x3-x0)*(x3-x1)*(x3-x2)))*y3;
writeln('x=',x,' ','Pol=',Pol,' = ','Factorial=',Factorial(x));
x:=x+100;
end;
end.
```