program RadixSortDescending;
uses sysutils;

type
    TArray = array of Integer;

procedure GenerateRandomArray(var arr: TArray; size: Integer);
var
    i: Integer;
begin
    Randomize;
    SetLength(arr, size);
    for i := 0 to size - 1 do
        arr[i] := Random(100); // Random numbers between 0 and 99
end;

procedure RadixSort(var arr: TArray);
var
    i, j, k, m, n, exp, max, temp: Integer;
    bucket: array[0..9] of TArray;
begin
    n := Length(arr);
    max := arr[0];
    
    for i := 1 to n - 1 do
        if arr[i] > max then
            max := arr[i];
    
    exp := 1;
    while max div exp > 0 do
    begin
        for i := 0 to 9 do
            SetLength(bucket[i], 0);
        
        for i := 0 to n - 1 do
        begin
            temp := (arr[i] div exp) mod 10;
            SetLength(bucket[temp], Length(bucket[temp]) + 1);
            bucket[temp][High(bucket[temp])] := arr[i];
        end;
        
        k := 0;
        for i := 9 downto 0 do
            for j := 0 to High(bucket[i]) do
            begin
                arr[k] := bucket[i][j];
                Inc(k);
            end;
        exp := exp * 10;
    end;
end;

var
    arr: TArray;
    i: Integer;
begin
    GenerateRandomArray(arr, 25);
    
    Writeln('Original array:');
    for i := 0 to High(arr) do
        Write(arr[i], ' ');
    Writeln;
    
    RadixSort(arr);
    
    Writeln('Sorted array in descending order:');
    for i := 0 to High(arr) do
        Write(arr[i], ' ');
    Writeln;
end.
 
by

Pascal online compiler

Write, Run & Share Pascal code online using OneCompiler’s Pascal online compiler for free. It’s a straightforward, accessible way to learn and experiment with Pascal programming right from your browser. OneCompiler supports modern Pascal syntax and provides a ready-to-use editor for immediate execution.

About Pascal

Pascal is a procedural programming language developed in the 1970s by Niklaus Wirth. It was designed to encourage good programming practices and structured programming. Pascal is widely used in teaching computer science fundamentals and has influenced many modern languages.

Sample Code

The following is a simple Pascal program that prints a greeting:

program HelloWorld;
begin
  writeln('Hello, OneCompiler!');
end.

Taking inputs (stdin)

OneCompiler’s Pascal editor supports stdin through the I/O tab. Here’s an example that reads a user's name and prints a greeting:

program GreetUser;
var
  name: string;
begin
  readln(name);
  writeln('Hello, ', name, '!');
end.

Syntax Basics

Variables

var
  age: integer;
  name: string;
  score: real;
  flag: boolean;

Data Types

TypeDescription
integerWhole numbers
realFloating-point numbers
charSingle character
stringSequence of characters
booleanTrue or False

Conditionals

if score >= 50 then
  writeln('Pass')
else
  writeln('Fail');

Loops

For loop

for i := 1 to 5 do
  writeln(i);

While loop

i := 1;
while i <= 5 do
begin
  writeln(i);
  i := i + 1;
end;

Repeat-Until loop

i := 1;
repeat
  writeln(i);
  i := i + 1;
until i > 5;

Procedures and Functions

procedure SayHello;
begin
  writeln('Hello!');
end;

function Add(a, b: integer): integer;
begin
  Add := a + b;
end;

This guide provides a quick reference to Pascal programming syntax and features. Start coding in Pascal using OneCompiler’s Pascal online compiler today!