Not sure why i used downto, thats just how i thought of it in my head.
EDIT: nvm, the reason i used downto is because when i do a factorial in my head or on a normal calculator i start from the high number and go down to 1
EDIT: the result:= result+1 works, i tested it before i used it.
EDIT3: new code:
var est,ii:extended;
function factorial(v:integer):integer;
var i:integer;
begin
for i := v downto 1 do
begin
result := result*i;
end;
end;
begin
est := 0
while not iskeydown(VK_RCONTROL) do
begin
est := ((pow(-1,ii)*factorial(int(6*ii))*(13591409+(545140134*ii)))/(pow(factorial(int(ii)),3)*factorial(int(3*ii))*pow(pow(640320,3),ii+(1/2))));
ii := ii+1;
writeln(12*est);
end;
end.
error:
[Error] (17:150): Type mismatch at line 16
Compiling failed.
Another edit:
using a different formula that finds the nth digit of pi:
ar P:string;k:integer;
begin
k:= 1;
while not iskeydown(VK_RCONTROL) do
begin
p := p+FloatToStr((pow(16,-1*k) * ( 4/((8*k)+1) - 2/((8*k)+4) - 1/((8*k)+5) - 1/((8*k)+6) ))) ;
inc(k);
end;
end.
error:
Math error at line 7.
EDIT:btw, the formula is for base16(i think that is hexadecimal) but i am using decimal, so how do i change it to hexadecimal
EDIT: i found out ther is a formula to calculate the nth digit of pi in any base but i cannot find a straight-forward answer, only essays that dont seem to give the formula.