Professional Documents
Culture Documents
What is an array: basically it is a holding position in memory similar to that of a variable. The
difference is that it has compartments called elements. Each element has an index number starting
with 1.
Demo drawing looks like this
1 2 3 4 5 6 7
index²1 index:=1;
While index <8 do While index <8 do
Get Marks(index) Readln (Marks[index]);
Index²index+1 Index²index+1;
9- To display the data in all elements, you need a For / While loop
For index = 1 to 7 do For index = 1 to 7 do
Pirnt Marks(index) Writeln (Marks[index]);
index²1 index:=1
While index <8 do While index <8 do
Print Marks(index) Writeln (Marks[index]);
Index²index+1 Index²index+1;
Note that the size of the loop is the same as the size of the array. This means that you can use a
constant which will allow you to change the size of the array without having to change anything else
in the code. Look at the below.
Here is the constant; call it n / LastNumber / ArraySize / something which makes sense.
10- To allow the user to input data in all elements, you need a For / While loop
Constant n ²7 Const n:=7;
For index = 1 to n do For index = 1 to n do
Get Marks(index) Readln (Marks[index]);
index²1 index:=1;
While index <n+1 do While index <n+1 do
Get Marks(index) Readln (Marks[index]);
Index²index+1 Index²index+1;