Arreglos en pascal
record;
set
type
vector= array [1..5] of integer;
fecha = array [i..3] of integer;
var
notas: vector;
i:int;
fech_ing:fecha;begin
fech_1[1]:=15;
fech_[2]:=03;
fech_3[3]:=1994;
cost
max_array=15
type
vector = array [1..max_array] of real;
rango+1..10;
vector2= array[1..rango] of boolean;inicializacion de arreglos
(*todo en cero*)
for (i:= 1) to 10 do
a[i]:=0;
(*2,4,6,..., 20*)
for 1:= 2 to 10 do
a[i]:=2*i;
(*desde la entrada*)
for i: 1 to 10 do
readln(a[i]);investigar: recorrido de arreglos, buscar un elemento en el arreglo, ordenar el arreglo.
recorrido de arreglos
la estructura de control for ees la adecuada para recorrercompletamente un arreglo
(*hallar la suma de todos los elementos*)
suma:=0;
for i:=a[i];
(*hallar el maximo*)
max:=a[i];
for i:=2 to m do
if a[i]>max then
max:=a[i];(*desplegar un arreglo*)
for i:1 to m do
writeln(a[i]);
(*Desplegar separados por comas*)
write(a[i]);
for i:=2 to m do
write(',',a[i]);
Busqueda de un arreglo
buscarun ejemplo que sea igual a A
i:=1;
repeat
exito:=(a[i]=A);
i:=i+1
until (i>m) or exito;
if exito then
writeln('exito')
else
writeln('fracaso')
usando whilei:=1;
exito:=false;
while(i<=m) and not exito do
begin
exito:=(a[i]=A);
i:=i+1
end;
if exito then
writeln('exito')
else
writeln('fracaso')
arreglo mutidimensionalmatriz[i][j]
type
matriz=array[1..4] of array[1..4] of integer
matriz=array[1..4, 1..4]
.
.
.
for i=1 to 4 do
for j=2 to 4 do
write (matriz[i][j]);
| J1 | J2| J3 | J4 |
I1 | 6 | 15 | 31 | 21 |
I2 | 15 | 23 | 73 | 62 |
I3 | 7 | 32 | 12 | 51 |
I4 | 13 | 343 | 34 | 21 |
Salida:
Matriz[1][1]=6
Matriz[1][2]=15
Matriz[3][3]=12
Regístrate para leer el documento completo.