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.




get "libhdr"
 
// Generate ASCII string of number n with ordinal suffix
// The string is stored at v.
let nth(n, v) = valof
$(  let sfx = "thstndrd"
    let c, s = 0, ?
    // Generate digits
    $(  c := c + 1
        v%c := n rem 10 + '0'
        n := n / 10
    $) repeatuntil n = 0
 
    // Put digits in correct order 
    for i = 1 to c/2 do
    $(  let d = v%i
        v%i := v%(c+1-i)
        v%(c+1-i) := d
    $)
 
    // The length of the string is the amount of digits + 2
    v%0 := c+2;
 
    // Figure out the proper suffix from the last two digits
    test v%(c-1)='1' | v%c>'3' 
        then s := 0
        else s := 2*(v%c - '0')
 
    v%(c+1) := sfx%(s+1)
    v%(c+2) := sfx%(s+2)
 
    resultis v
$)
 
let start() be
$(  let buf = vec 10
    for i =    0 to   25 do writef("%S*N", nth(i, buf))
    for i =  250 to  265 do writef("%S*N", nth(i, buf))
    for i = 1000 to 1025 do writef("%S*N", nth(i, buf))
$)