Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
program Ordering;
var
sortArray: array [0..9] of integer;
count, tempNumber: integer;
mode: string;
swapMade: boolean;
begin
repeat
write('Ascending [1] or descending [2]? ');
readln(mode);
until (mode = '1') or (mode = '2');
for count := 0 to 9 do
begin
write('Enter a number: ');
readln(tempNumber);
sortArray[count] := tempNumber;
end;
repeat
swapMade := false;
for count := 0 to 8 do
if sortArray[count] > sortArray[count + 1] then
begin
tempNumber := sortArray[count];
sortArray[count] := sortArray[count + 1];
sortArray[count + 1] := tempNumber;
swapMade := true;
end;
until not swapMade;
if mode = '1' then
for count := 0 to 9 do
writeln(sortArray[count]);
if mode = '2' then
for count := 0 to 9 do
writeln(sortArray[9 - count]);
readln;
end.
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more