Programa que muestra cuales son los valores menor y mayor dados de un vector
pascal:
{-Victor De la Rocha}
{-Algoritmia@groups.msn.com}
{-www.myalgorithm.com}
uses
crt;
type
vector=array [1..100] of integer;
var
arreglo:vector;
cantidad,cont1,cont2,temp1,temp2:integer;
begin
ClrScr;
Write('Cantidad de valores: ');Readln(cantidad);
writeln;
for cont1:=1 to cantidad do
begin
Write('Valor ',cont1,': ');Readln(arreglo[cont1]);
end;
for cont1:=cantidad downto 1 do
begin
for cont2:=1 to cont1 do
begin
if arreglo[cont1]>arreglo[cont2] then
begin
temp1:=arreglo[cont1];
temp2:=arreglo[cont2];
arreglo[cont1]:=temp2;
arreglo[cont2]:=temp1;
end;
end;
end;
writeln('El valor mayor es: ',arreglo[1]);
write('El valor menor es: ',arreglo[cantidad]);
ReadKey;
end.
{-Algoritmia@groups.msn.com}
{-www.myalgorithm.com}
uses
crt;
type
vector=array [1..100] of integer;
var
arreglo:vector;
cantidad,cont1,cont2,temp1,temp2:integer;
begin
ClrScr;
Write('Cantidad de valores: ');Readln(cantidad);
writeln;
for cont1:=1 to cantidad do
begin
Write('Valor ',cont1,': ');Readln(arreglo[cont1]);
end;
for cont1:=cantidad downto 1 do
begin
for cont2:=1 to cont1 do
begin
if arreglo[cont1]>arreglo[cont2] then
begin
temp1:=arreglo[cont1];
temp2:=arreglo[cont2];
arreglo[cont1]:=temp2;
arreglo[cont2]:=temp1;
end;
end;
end;
writeln('El valor mayor es: ',arreglo[1]);
write('El valor menor es: ',arreglo[cantidad]);
ReadKey;
end.
Cantidad: 30 Valor 1: 79 Valor 2: 55 Valor 3: 41 Valor 4: 71 Valor 5: 66 Valor 6: 62 Valor 7: 64 Valor 8: 78 Valor 9: 43 Valor 10: 26 Valor 11: 82 Valor 12: 51 Valor 13: 7 Valor 14: 6 Valor 15: 67 Valor 16: 28 Valor 17: 5 Valor 18: 12 Valor 19: 41 Valor 20: 91 Valor 21: 35 Valor 22: 3 Valor 23: 76 Valor 24: 75 Valor 25: 43 Valor 26: 89 Valor 27: 93 Valor 28: 63 Valor 29: 25 Valor 30: 27 Valor mayor: 93 Valor menor: 3