Home computickets Runtime error: Index was out of bounds of array

Runtime error: Index was out of bounds of array

Author

Date

Category

PascalABC.NET how to fix the error?

uses Arrays;
var
 a: array of integer;
 N: integer;
 i1, i2: integer;
begin
 N: = 50;
 a: = CreateRandomIntegerArray (50);
 for var i: = 1 to N do begin
  if a [i] & gt; 0 then
  i1 + = 1;
  if a [i] & lt; 0 then
  i2 + = 1;
  end;
write (i1);
write (i2);
end.

Answer 1, authority 100%

Dynamic arrays are numbered from zero. The loop for var i: = 1 to N do begin should at least look like this for var i: = 0 to N-1 do begin

In general, it is worth operating with such array functions as length , High , etc.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions