Vilmis Neviera - 1 year ago 176
Pascal Question

# Pascal arranging array, with a row number

``````type
mas = array [1 .. 10000] of real;

var
n: integer;
a: mas;
Rf: text;

Procedure Skaityti;
var
i: integer;
Df: text;
begin
Assign(Df, 'duom1.txt');
Reset(Df);
for i := 1 to n do
Close(Df);
end;

Procedure MinMax(var min, max, nrmin, nrmax, vid: real);
var
i: integer;
begin
min := a[1];
max := a[1];
nrmin := 1;
nrmax := 1;
for i := 1 to n do
begin
if min > a[i] then
begin
min := a[i];
nrmin := i;
end;
if max < a[i] then
begin
max := a[i];
nrmax := i;
end;
vid := vid + a[i];
end;
vid := vid / n;
end;

var
min, max, nrmin, nrmax, vid: real;

begin
Skaityti;
MinMax(min, max, nrmin, nrmax, vid);
Assign(Rf, 'rez.txt');
Rewrite(Rf);
WriteLn(Rf, 'biggest amount     ', max:7:2, '   number ', nrmax:7:0);
WriteLn(Rf, 'smallest  amount     ', min:7:2, '   number', nrmin:7:0);
WriteLn(Rf, 'average amount       ', vid:7:2);
WriteLn(Rf);
WriteLn(Rf, 'number   amount');
Close(Rf);
end.
``````

This is the code and it Reads elements from a .txt file to an array, I created procedure to find biggest and smallest value of it. Now I need to create a procedure to write my array from biggest to smallest and a row number next to it. It should look something like this:

``````Row number       value
5             1000000
6             999999
8             888888
``````

and so on.. Any ideas ?

P.S. I can arrange that array to be from biggest to smallest but then the row numbers will mess up :/