Jump to content

[PASCAL] Output an array


CouldnoT
 Share

Recommended Posts

Array output

 

Before reading this I suggest you to have a look at the for loop, click.

 

Arrays

 

An Array is a chain of variables of the same type. If we need to declare an array of 10 Integer variables, we can do it like this:

 Numbers: array [1 .. 10] of Integer;

 

We can access single variables in the array using its index. For example, to put a value in the first variable in the array we can write it as:

 Numbers[1]:= 30;

 

To put a value in the second variable, use the index 2:

 Numbers[2]:= 315;

 

Output an array

 

We need to use the for loop in case you want to output an array. As the example shown here :

 

program tab;
uses wincrt;

type
tab = array [1..5] of char;

var
t:tab; 
c, j: Integer;

begin
t[1]:= 'A';
t[2]:= 'B';
t[3]:= 'C';
t[4]:= 'D';
t[5]:= 'E';


for j:=1 to 5 do 
	begin
	write(' | ', j);
	end;
        writeln;
	for c:=1 to 5 do
	    begin
		write(' | ' ,t[c]);	
	    end;	

readln;
end.

 

 

 

Edited by CouldnoT
Link to comment
Share on other sites

  • CouldnoT changed the title to [PASCAL] Output an array
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.