In Pascal. An array of N real numbers is given (N can be no more than 25). Sort negative numbers
In Pascal. An array of N real numbers is given (N can be no more than 25). Sort negative numbers in the given array in descending order of their values. Keep the relative position of negative and positive numbers. Display the original and new arrays.
program zz1;
const n = 15; // set the number of numbers in the array
var i, k, j: integer; // set variables of integer type
b: real;
m, v: array [1..n] of real;
begin
for i: = 1 to n do // get n random numbers and write them into an array
m [i]: = random (51) -25 + random;
for i: = 1 to n do // display the original array on the screen
write (m [i]: 8: 2);
writeln; // go to a new line to display the response
for i: = 1 to n do
if m [i] <0 then begin k: = k + 1; v [k]: = m [i]; end;
for i: = 1 to k-1 do
for j: = 1 to k-i do
if v [j] <v [j + 1] then begin
b: = v [j];
v [j]: = v [j + 1];
v [j + 1]: = b;
end;
k: = 0;
for i: = 1 to n do
if m [i] <0 then begin k: = k + 1; m [i]: = v [k]; end;
for i: = 1 to n do // display the resulting array on the screen
write (m [i]: 8: 2);
end.