0% found this document useful (0 votes)
3 views2 pages

Array

The document contains several Pascal programs demonstrating the use of arrays. It includes examples of summing array elements, initializing an array with squares of indices, and using arrays to store strings instead of individual variables. Each program illustrates different aspects of array manipulation in Pascal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Array

The document contains several Pascal programs demonstrating the use of arrays. It includes examples of summing array elements, initializing an array with squares of indices, and using arrays to store strings instead of individual variables. Each program illustrates different aspects of array manipulation in Pascal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

01.

program SUM_ARRAY(input, output);


TYPE
IntArray = array[1..5] of integer;

VAR
i, sum: integer;
numbers : IntArray;

begin
sum := 0;
numbers[1] := 3;
numbers[2] := 7;
numbers[3] := 2;
numbers[4] := 4;
numbers[5] := 5;

for i := 1 to 5 do
sum := sum + numbers[1];
writeln('sum = ', sum);
end.

02. program arrayExample1;


var
arr: array [0..4] of integer;
i: integer;

begin

for i := 0 to 4 do
arr[i] := i * i;

for i:= 0 to 4 do
writeln('arr[', i, '] = ', arr[i] );
end.

03. var
a : array[1..10] of byte;

begin
a[1]:=10;
a[2]:=15;
a[3]:=a[1]+a[2];
writeln(a[1]);
writeln(a[2]);
writeln(a[3]);
end.

04. var
names : array[1..10] of string;

rather than having each variables like this :

var
name1, name2, name3, name4, name5,
name6, name7, name8, name9, name10 : string;

Array makes us easier in writing the contents. Writing all the names with an array
names above, would be :

for i:=1 to 10 do
writeln(names[i]);

05.

You might also like