• Lenguaje

    Pascal

  • Descripción

    Pide al usuario N números, los guarda en un arreglo, ordena el arreglo de menor a mayor con el método de la burbuja y muestra el arreglo ordenado

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
program burbujan;
uses crt;

type realarray  = array[0..0] of real;
type prealarray = ^realarray;
var aux : real;
var numeros : prealarray;
var i, j, n : integer;
var tecla : char;
begin
    write ('Ingrese el n'#163'mero de elementos: ');
    readln (n);
    getmem (numeros, sizeof (prealarray) * n);
    for i := 0 to n - 1 do
        begin
            write ('Ingrese el valor del elemento ', i, ': ');
            readln (numeros^[i]);
        end;
    for i:=1 to n - 1 do
        for j := 0 to n - i - 1 do
            if (numeros^[j] > numeros^[j + 1]) then
                begin
                    aux := numeros^[j];
                    numeros^[j] := numeros^[j + 1];
                    numeros^[j + 1] := aux;
                end;
    writeln (#10#13'N'#163'meros ordenados:');
    for i:=0 to n - 1 do
        writeln ('[', i , ']: ', numeros^[i]:0:2);
    write (#10#13'Presione una tecla para terminar . . . ');
    tecla := readkey;
end.