I tried to run the following code but it shows an error regarding memory address and shows a message that \'n maybe undefined after the loop\'. Please have a look.
You don't allocate any memory for the arrays. You need to call to SetLength
to do that.
SetLength(r, n_max);
// and likewise for the other arrays
What's more, the loop does nothing. The loop contains a single statement which is an empty statement terminated by the semi-colon after the do
.
for n := 0 to n_max-1 do;
// yes, that semi-colon is the end of the loop
You'll need a begin
/end
block.
for n := 0 to n_max-1 do
begin
// loop body goes in here
....
end;
// at this point, outside the loop, the value of n is ill-defined.