Write a function/method/subroutine/... that when given an integer greater than or equal to zero returns a string of the number followed by an apostrophe then the ordinal suffix.



Example

Returns would include 1'st 2'nd 3'rd 11'th 111'th 1001'st 1012'th



Task

Use your routine to show here the output for at least the following (inclusive) ranges of integer inputs:
0..25, 250..265, 1000..1025


Note: apostrophes are now optional to allow correct apostrophe-less English.




 
MODULE Nth;
 
FROM STextIO IMPORT
  WriteString, WriteLn;
FROM WholeStr IMPORT
  IntToStr;
 
PROCEDURE Suffix(N: CARDINAL; VAR OUT Destination: ARRAY OF CHAR);
VAR
  NMod10, NMod100: CARDINAL;
BEGIN
  NMod10 := N MOD 10;
  NMod100 := N MOD 100;
  IF (NMod10 = 1) AND (NMod100 <> 11) THEN
    Destination := "st";
  ELSIF (NMod10 = 2) AND (NMod100 <> 12) THEN
    Destination := "nd";
  ELSIF (NMod10 = 3) AND (NMod100 <> 13) THEN
    Destination := "rd";
  ELSE
    Destination := "th";
  END;
END Suffix;
 
PROCEDURE PrintImages(LoLim, HiLim: CARDINAL);
VAR
  I: CARDINAL;
  IString: ARRAY [0 .. 15] OF CHAR;
  ISuff: ARRAY [0 .. 1] OF CHAR;
BEGIN
  FOR I := LoLim TO HiLim DO
    IntToStr(I, IString);
    Suffix(I, ISuff);
    WriteString(IString);
    WriteString(ISuff);
    WriteString(" ");
  END;
  WriteLn;
END PrintImages;
 
BEGIN
  PrintImages(   0,   25);
  PrintImages( 250,  265);
  PrintImages(1000, 1025);
END Nth.
 