Jump to content

N'th: Difference between revisions

33,043 bytes added ,  1 month ago
m
fix typo
m (fix typo)
 
(48 intermediate revisions by 22 users not shown)
Line 20:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V _suffix = [‘th’, ‘st’, ‘nd’, ‘rd’, ‘th’, ‘th’, ‘th’, ‘th’, ‘th’, ‘th’]
 
F nth(n)
Line 26:
 
L(j) (0..1000).step(250)
print_elements(Array(j.+25).map(i -> nth(i)))</langsyntaxhighlight>
 
{{out}}
Line 36:
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th
</pre>
 
=={{header|68000 Assembly}}==
The function itself:
<syntaxhighlight lang="68000devpac">Nth:
MOVEQ #1,D1
.loop:
MOVE.L D1,-(SP)
MOVE.L D0,-(SP)
MOVE.B (2,SP),D0
JSR printhex
MOVE.B (3,SP),D0
JSR printhex
MOVE.L (SP)+,D0
MOVE.L D0,-(SP)
AND.W #$00FF,D0
;HANDLE SPECIAL CASES
CMP.B #$11,D0
BEQ .fourth
CMP.B #$12,D0
BEQ .fourth
CMP.B #$13,D0
BEQ .fourth
;HANDLE THE REST
AND.W #$000F,D0
CMP.B #1,D0
BEQ .first
CMP.B #2,D0
BEQ .second
CMP.B #3,D0
BEQ .third
.fourth:
LEA th,A3
bra .print
.third:
LEA rd,a3
bra .print
.second:
LEA nd,a3
bra .print
.first:
LEA est,a3
.print:
JSR PrintString
JSR newline
MOVE.L (SP)+,d0
MOVE.L (SP)+,d1
ABCD D1,D0
DBRA D7,.loop
rts
 
th:
dc.b "th",255
even
est:
dc.b "st",255
even
nd:
dc.b "nd",255
even
rd:
dc.b "rd",255
even</syntaxhighlight>
 
And the test cases (each was executed in separate builds of the Sega Genesis cartridge to have enough room to see them all at once)
<syntaxhighlight lang="68000devpac">MOVE.w #0,D0
MOVE.W #25,D7
JSR Nth
 
MOVE.w #$250,D0 ;since we're working with binary-coded decimal, this number is stored as hex.
MOVE.W #15,D7
JSR Nth
 
MOVE.w #$1000,D0 ;since we're working with binary-coded decimal, this number is stored as hex.
MOVE.W #25,D7
JSR Nth
 
jmp * ;stop the cpu - we're done.</syntaxhighlight>
 
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="asm"> org 100h
jmp demo
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 114 ⟶ 196:
dcr b ; Decrement counter
jnz printnums ; If not zero, print next number
ret</langsyntaxhighlight>
 
{{out}}
Line 130 ⟶ 212:
{{trans|8080 Assembly}}
 
<langsyntaxhighlight lang="asm"> bits 16
cpu 8086
segment .text
Line 187 ⟶ 269:
dec bl ; Are we done yet?
jnz printn
ret</langsyntaxhighlight>
 
{{out}}
Line 201 ⟶ 283:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Nth(CARD val,CHAR ARRAY s)
CHAR ARRAY sfx
BYTE d
Line 239 ⟶ 321:
PutE() PutE()
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/N'th.png Screenshot from Atari 8-bit computer]
Line 252 ⟶ 334:
=={{header|Ada}}==
 
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
 
procedure Nth is
Line 277 ⟶ 359:
Print_Images( 250, 265);
Print_Images(1000, 1025);
end Nth;</langsyntaxhighlight>
 
{{Out}}
Line 286 ⟶ 368:
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.6.win32}}
<langsyntaxhighlight lang="algol68"># PROC to suffix a number with st, nd, rd or th as appropriate #
PROC nth = ( INT number )STRING:
BEGIN
Line 334 ⟶ 416:
test nth( 1000, 1025 )
 
)</langsyntaxhighlight>
{{out}}
<pre>
Line 349 ⟶ 431:
1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd
1024th 1025th
 
</pre>
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">
begin % suffix number with st, nd, rd or th as appropriate %
 
string(2) procedure ordinalSuffix ( integer value number ) ;
begin
integer numberRem100;
numberRem100 := number rem 100;
if numberRem100 >= 10 and numberRem100 <= 20 then begin
% numbers in the range 10 .. 20 always have "th" %
"th"
end
else begin
% not in the range 10 .. 20, suffix is st, nd, rd or th %
% depending on the final digit %
integer numberRem10;
numberRem10 := number rem 10;
if numberRem10 = 1 then "st"
else if numberRem10 = 2 then "nd"
else if numberRem10 = 3 then "rd"
else "th"
end if_numberRem100_in_10_to_20__
end ordinalSuffix ;
 
% tests ordinalSuffix, displays the suffix for all numbers in from .. to %
procedure testSuffix ( integer value from, to ) ;
begin
integer count;
count := 0;
for testValue := from until to do begin
writeon( i_w := 4, s_w := 0, " ", testValue, ordinalSuffix( testValue ) );
count := count + 1;
if count rem 8 = 0 then write()
end for_testValue ;
if count rem 8 not = 0 then write();
write()
end testSuffix ;
 
begin % task %
testSuffix( 0, 25 );
testSuffix( 250, 265 );
testSuffix( 1000, 1025 )
end
end.
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th
8th 9th 10th 11th 12th 13th 14th 15th
16th 17th 18th 19th 20th 21st 22nd 23rd
24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th
258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th
1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th
1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd
1024th 1025th
 
</pre>
Line 355 ⟶ 499:
{{works with|Dyalog APL}}
 
<langsyntaxhighlight APLlang="apl"> nth←{
sfx←4 2⍴'stndrdth'
tens←(10<100|⍵)∧20>100|⍵
(⍕⍵),sfx[(4×tens)⌈(⍳3)⍳10|⍵;]
}</langsyntaxhighlight>
 
{{out}}
Line 377 ⟶ 521:
 
=={{header|AppleScript}}==
<langsyntaxhighlight AppleScriptlang="applescript">-- ORDINAL STRINGS -----------------------------------------------------------
 
-- ordinalString :: Int -> String
Line 458 ⟶ 602:
end |λ|
end script
end uncurry</langsyntaxhighlight>
{{Out}}
<pre>{{"0th", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th",
Line 469 ⟶ 613:
"1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th",
"1021st", "1022nd", "1023rd", "1024th", "1025th"}}</pre>
 
=={{header|Applesoft BASIC}}==
<lang ApplesoftBasic>0 OP = 1
10 FOR N = 0 TO 25 : GOSUB 100 : NEXT
20 FOR N = 250 TO 265 : GOSUB 100 : NEXT
30 FOR N = 1000 TO 1025 : GOSUB 100 : NEXT
40 END
 
100 GOSUB 200"NTH
110 PRINT NTH$ " ";
120 RETURN
 
200 M1 = N - INT(N / 10) * 10
210 M2 = N - INT(N / 100) * 100
220 NTH$ = "TH"
230 IF M1 = 1 AND M2 <> 11 THEN NTH$ = "ST"
240 IF M1 = 2 AND M2 <> 12 THEN NTH$ = "ND"
250 IF M1 = 3 AND M2 <> 13 THEN NTH$ = "RD"
260 IF NOT OP THEN NTH$ = "'" + NTH$
270 NTH$ = STR$(N) + NTH$
280 RETURN</lang>
{{Out}}
<pre>0'TH 1'ST 2'ND 3'RD 4'TH 5'TH 6'TH 7'TH 8'TH 9'TH 10'TH 11'TH 12'TH 13'TH 14'TH 15'TH 16'TH 17'TH 18'TH 19'TH 20'TH 21'ST 22'ND 23'RD 24'TH 25'TH 250'TH 251'ST 252'ND 253'RD 254'TH 255'TH 256'TH 257'TH 258'TH 259'TH 260'TH 261'ST 262'ND 263'RD 264'TH 265'TH 1000'TH 1001'ST 1002'ND 1003'RD 1004'TH 1005'TH 1006'TH 1007'TH 1008'TH 1009'TH 1010'TH 1011'TH 1012'TH 1013'TH 1014'TH 1015'TH 1016'TH 1017'TH 1018'TH 1019'TH 1020'TH 1021'ST 1022'ND 1023'RD 1024'TH 1025'TH</pre>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">suffixes: ["th" "st" "nd" "rd" "th" "th" "th" "th" "th" "th"]
nth: function [n][
Line 507 ⟶ 628:
prints (nth i)++" "
print ""
]</langsyntaxhighlight>
 
{{out}}
Line 519 ⟶ 640:
=={{header|AutoHotkey}}==
{{works with|AutoHotkey 1.1}}
<langsyntaxhighlight AutoHotkeylang="autohotkey">for k, v in [[0, 25], [250, 265], [1000, 1025]] {
while v[1] <= v[2] {
Out .= Ordinal(v[1]) " "
Line 534 ⟶ 655:
s1 := Mod(n, 10)
return n (s1 = 1 ? "st" : s1 = 2 ? "nd" : s1 = 3 ? "rd" : "th")
}</langsyntaxhighlight>
{{Out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 541 ⟶ 662:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f NTH.AWK
BEGIN {
Line 574 ⟶ 695:
return(nthday)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 584 ⟶ 705:
=={{header|Babel}}==
 
<langsyntaxhighlight lang="babel">((irregular ("st" "nd" "rd"))
 
(main
Line 611 ⟶ 732:
. . }
{ -> %d "'th" . }
ifte }))</langsyntaxhighlight>
 
{{out}}
Line 624 ⟶ 745:
1008'th 1007'th 1006'th 1005'th 1004'th 1003'rd 1002'nd 1001'st 1000'th</pre>
 
=={{header|BaConBASIC}}==
==={{header|ANSI BASIC}}===
<lang freebasic>' Nth (sans apostrophes)
{{trans|Ada}}
{{works with|Decimal BASIC}}
<syntaxhighlight lang="basic">
100 REM Nth
110 DECLARE EXTERNAL FUNCTION Suffix$
120 DECLARE EXTERNAL SUB PrintImages
130 CALL PrintImages(0, 25)
140 CALL PrintImages(250, 265)
150 CALL PrintImages(1000, 1025)
160 END
170 REM
180 EXTERNAL SUB PrintImages(LoLim, HiLim)
190 FOR I = LoLim TO HiLim
200 PRINT STR$(I); Suffix$(I); " ";
210 NEXT I
220 PRINT
230 END SUB
240 REM
250 EXTERNAL FUNCTION Suffix$(N)
260 LET NMod10 = MOD(N, 10)
270 LET NMod100 = MOD(N, 100)
280 IF NMod10 = 1 AND NMod100 <> 11 THEN
290 LET Suffix$ = "st"
300 ELSEIF NMod10 = 2 AND NMod100 <> 12 THEN
310 LET Suffix$ = "nd"
320 ELSEIF NMod10 = 3 AND NMod100 <> 13 THEN
330 LET Suffix$ = "rd"
340 ELSE
350 LET Suffix$ = "th"
360 END IF
370 END FUNCTION
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
==={{header|Applesoft BASIC}}===
<syntaxhighlight lang="applesoftbasic">0 OP = 1
10 FOR N = 0 TO 25 : GOSUB 100 : NEXT
20 FOR N = 250 TO 265 : GOSUB 100 : NEXT
30 FOR N = 1000 TO 1025 : GOSUB 100 : NEXT
40 END
 
100 GOSUB 200"NTH
110 PRINT NTH$ " ";
120 RETURN
 
200 M1 = N - INT(N / 10) * 10
210 M2 = N - INT(N / 100) * 100
220 NTH$ = "TH"
230 IF M1 = 1 AND M2 <> 11 THEN NTH$ = "ST"
240 IF M1 = 2 AND M2 <> 12 THEN NTH$ = "ND"
250 IF M1 = 3 AND M2 <> 13 THEN NTH$ = "RD"
260 IF NOT OP THEN NTH$ = "'" + NTH$
270 NTH$ = STR$(N) + NTH$
280 RETURN</syntaxhighlight>
{{Out}}
<pre>0'TH 1'ST 2'ND 3'RD 4'TH 5'TH 6'TH 7'TH 8'TH 9'TH 10'TH 11'TH 12'TH 13'TH 14'TH 15'TH 16'TH 17'TH 18'TH 19'TH 20'TH 21'ST 22'ND 23'RD 24'TH 25'TH 250'TH 251'ST 252'ND 253'RD 254'TH 255'TH 256'TH 257'TH 258'TH 259'TH 260'TH 261'ST 262'ND 263'RD 264'TH 265'TH 1000'TH 1001'ST 1002'ND 1003'RD 1004'TH 1005'TH 1006'TH 1007'TH 1008'TH 1009'TH 1010'TH 1011'TH 1012'TH 1013'TH 1014'TH 1015'TH 1016'TH 1017'TH 1018'TH 1019'TH 1020'TH 1021'ST 1022'ND 1023'RD 1024'TH 1025'TH</pre>
 
==={{header|BaCon}}===
<syntaxhighlight lang="freebasic">' Nth (sans apostrophes)
FUNCTION nth$(NUMBER n) TYPE STRING
LOCAL suffix
Line 652 ⟶ 836:
NEXT
NEXT
DATA 0, 25, 250, 265, 1000, 1025, -20, -11</langsyntaxhighlight>
 
{{out}}
Line 666 ⟶ 850:
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
<lang BASIC256>
function ordinal(n)
ns$ = string(n)
Line 697 ⟶ 880:
call imprimeOrdinal (1000, 1025)
end
</syntaxhighlight>
</lang>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> PROCNth( 0, 25)
PROCNth( 250, 265)
PROCNth(1000,1025)
END
 
DEF PROCNth(s%,e%)
LOCAL i%,suff$
FOR i%=s% TO e%
suff$="th"
IF i% MOD 10 = 1 AND i% MOD 100 <> 11 suff$="st"
IF i% MOD 10 = 2 AND i% MOD 100 <> 12 suff$="nd"
IF i% MOD 10 = 3 AND i% MOD 100 <> 13 suff$="rd"
PRINT STR$i%+suff$+" ";
NEXT
PRINT
ENDPROC</syntaxhighlight>
 
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|BASIC256}}
<syntaxhighlight lang="qbasic">100 cls
110 imprimeordinal(0,25)
120 print : print
130 imprimeordinal(250,265)
140 print : print
150 imprimeordinal(1000,1025)
160 print
170 end
180 sub ordinal$(n)
190 ns$ = str$(n)
200 ordinal$ = ""
210 select case right$(ns$,1)
220 case "1"
230 if right$(ns$,2) = "11" then ordinal$ = ns$+"th" : goto 340
240 ordinal$ = ns$+"st" : goto 340
250 case "2"
260 if right$(ns$,2) = "12" then ordinal$ = ns$+"th" : goto 340
270 ordinal$ = ns$+"nd" : goto 340
280 case "3"
290 if right$(ns$,2) = "13" then ordinal$ = ns$+"th" : goto 340
300 ordinal$ = ns$+"rd" : goto 340
310 case else
320 ordinal$ = ns$+"th" : goto 340
330 end case
340 return
350 sub imprimeordinal(a,b)
360 for i = a to b
370 print ordinal$(i);" ";
380 next i
390 return</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
{{trans|Applesoft BASIC}}
{{works with|Commodore BASIC|2.0}}
<syntaxhighlight lang="basic">
0 REM ROSETTACODE.ORG
1 REM N'TH
2 REM WRITE A FUNCTION/METHOD/SUBROUTINE/... THAT WHEN GIVEN AN INTEGER GREATER
3 REM THAN OR EQUAL TO ZERO RETURNS A STRING OF THE NUMBER FOLLOWED BY
4 REM AN APOSTROPHE THEN THE ORDINAL SUFFIX.
5 REM BASED ON APPLESOFT BASIC VERSION @ ROSETTACODE.ORG
6 REM
7 REM *************************
8 PRINT CHR$(14): REM CHANGE TO LOWER/UPPER CASE CHAR SET
9 OP = 1
10 FOR N = 0 TO 25 : GOSUB 100 : NEXT : PRINT
20 FOR N = 250 TO 265 : GOSUB 100 : NEXT : PRINT
30 FOR N = 1000 TO 1025 : GOSUB 100 : NEXT : PRINT
40 END
50 REM *************************
100 GOSUB 200
110 PRINT NTH$ " ";
120 RETURN
130 REM ************************
200 M1 = N - INT(N / 10) * 10
210 M2 = N - INT(N / 100) * 100
220 NTH$ = "TH"
230 IF M1 = 1 AND M2 <> 11 THEN NTH$ = "ST"
240 IF M1 = 2 AND M2 <> 12 THEN NTH$ = "ND"
250 IF M1 = 3 AND M2 <> 13 THEN NTH$ = "RD"
260 IF NOT OP THEN NTH$ = "'" + NTH$
270 NTH$ = STR$(N) + NTH$
280 RETURN
</syntaxhighlight>
{{out}}
Commodore 64 (40 column text)
<pre>
0'th 1'st 2'nd 3'rd 4'th 5'th 6't
h 7'th 8'th 9'th 10'th 11'th 12'th
13'th 14'th 15'th 16'th 17'th 18'
th 19'th 20'th 21'st 22'nd 23'rd 2
4'th 25'th
250'th 251'st 252'nd 253'rd 254'th
255'th 256'th 257'th 258'th 259'th
260'th 261'st 262'nd 263'rd 264'th
265'th
1000'th 1001'st 1002'nd 1003'rd 100
4'th 1005'th 1006'th 1007'th 1008'th
1009'th 1010'th 1011'th 1012'th 10
13'th 1014'th 1015'th 1016'th 1017't
h 1018'th 1019'th 1020'th 1021'st 1
022'nd 1023'rd 1024'th 1025'th
</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
' Apostrophes NOT used as incorrect English
 
Function ordinal(n As UInteger) As String
Dim ns As String = Str(n)
Select Case Right(ns, 1)
Case "0", "4" To "9"
Return ns + "th"
Case "1"
If Right(ns, 2) = "11" Then Return ns + "th"
Return ns + "st"
Case "2"
If Right(ns, 2) = "12" Then Return ns + "th"
Return ns + "nd"
Case "3"
If Right(ns, 2) = "13" Then Return ns + "th"
Return ns + "rd"
End Select
End Function
 
Dim i As Integer
For i = 0 To 25
Print ordinal(i); " ";
Next
Print : Print
 
For i = 250 To 265
Print ordinal(i); " ";
Next
Print : Print
 
For i = 1000 To 1025
Print ordinal(i); " ";
Next
Print : Print
 
Print "Press any key to quit"
Sleep</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th
1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=6d60749ae886a37f128e75cffc6c7118 Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim siNums As Short[] = [0, 25, 250, 265, 1000, 1025]
Dim siCount, siNumbers As Short
Dim sOrdinal As String
 
For siNumbers = 0 To 4 Step 2
For siCount = siNums[siNumbers] To siNums[siNumbers + 1]
sOrdinal = "th"
If Right(Str(siCount), 1) = "1" And Right(Str(siCount), 2) <> "11" Then sOrdinal = "st"
If Right(Str(siCount), 1) = "2" And Right(Str(siCount), 2) <> "12" Then sOrdinal = "nd"
If Right(Str(siCount), 1) = "3" And Right(Str(siCount), 2) <> "13" Then sOrdinal = "rd"
Print siCount & sOrdinal;;
Next
Print gb.NewLine
Next
 
End </syntaxhighlight>
Output:
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
==={{header|GW-BASIC}}===
{{trans|Ada}}
{{works with|PC-BASIC|any}}
<syntaxhighlight lang="qbasic">
10 ' N'th
20 LET LOLIM% = 0
30 LET HILIM% = 25
40 GOSUB 1000
50 LET LOLIM% = 250
60 LET HILIM% = 265
70 GOSUB 1000
80 LET LOLIM% = 1000
90 LET HILIM% = 1025
100 GOSUB 1000
110 END
995 ' Print images
1000 FOR I% = LOLIM% TO HILIM%
1010 LET NR% = I%
1020 GOSUB 1500
1030 LET SI$ = STR$(I%)
1040 PRINT RIGHT$(SI$, LEN(SI$) - 1); SUF$; " ";
1050 NEXT I%
1060 PRINT
1070 RETURN
 
1495 ' Get suffix
1500 IF (NR% MOD 10 = 1) AND (NR% MOD 100 <> 11) THEN LET SUF$ = "st": GOTO 2000
1600 IF (NR% MOD 10 = 2) AND (NR% MOD 100 <> 12) THEN LET SUF$ = "nd": GOTO 2000
1700 IF (NR% MOD 10 = 3) AND (NR% MOD 100 <> 13) THEN LET SUF$ = "rd": GOTO 2000
1800 LET SUF$ = "th"
2000 RETURN
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
==={{header|Liberty BASIC}}===
{{trans|Ada}}
{{works with|Just BASIC|any}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">
call printImages 0, 25
call printImages 250, 265
call printImages 1000, 1025
end
 
sub printImages loLim, hiLim
loLim = int(loLim)
hiLIm = int(hiLim)
for i = loLim to hiLim
print str$(i) + suffix$(i) + " ";
next i
print
end sub
 
function suffix$(n)
n = int(n)
nMod10 = n mod 10
nMod100 = n mod 100
if (nMod10 = 1) and (nMod100 <> 11) then
suffix$ = "st"
else
if (nMod10 = 2) and (nMod100 <> 12) then
suffix$ = "nd"
else
if (NMod10 = 3) and (NMod100 <> 13) then
suffix$ = "rd"
else
suffix$ = "th"
end if
end if
end if
end function
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3th 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23th 24th 25th
250th 251st 252nd 253th 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263th 264th 265th
1000th 1001st 1002nd 1003th 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023th 1024th 1025th
</pre>
 
==={{header|Microsoft Small Basic}}===
{{trans|Ada}}
<syntaxhighlight lang="microsoftsmallbasic">
loLim = 0
hiLim = 25
PrintImages()
loLim = 250
hiLim = 265
PrintImages()
loLim = 1000
hiLim = 1025
PrintImages()
Sub PrintImages
For i = loLim To hiLim
nr = i
GetSuffix()
TextWindow.Write(i + suffix + " ")
EndFor
TextWindow.WriteLine("")
EndSub
Sub GetSuffix
rem10 = Math.Remainder(nr, 10)
rem100 = Math.Remainder(nr, 100)
If rem10 = 1 And rem100 <> 11 Then
suffix = "st"
ElseIf rem10 = 2 And rem100 <> 12 Then
suffix = "nd"
ElseIf rem10 = 3 And rem100 <> 13 Then
suffix = "rd"
Else
suffix = "th"
EndIf
EndSub
</syntaxhighlight>
 
==={{header|Nascom BASIC}}===
{{trans|Ada}}
{{works with|Nascom ROM BASIC|4.7}}
<syntaxhighlight lang="basic">
10 REM N'th
20 LOLIM=0
30 HILIM=25
40 GOSUB 1000
50 LOLIM=250
60 HILIM=265
70 GOSUB 1000
80 LOLIM=1000
90 HILIM=1025
100 GOSUB 1000
110 END
995 REM ** Print images
1000 FOR I=LOLIM TO HILIM
1010 NR=I
1020 GOSUB 1500
1030 SI$=STR$(I)
1040 PRINT RIGHT$(SI$,LEN(SI$)-1);SUF$;" ";
1050 NEXT I
1060 PRINT
1070 RETURN
1495 REM ** Get suffix
1500 LA=NR-INT(NR/10)*10:NLA=NR-INT(NR/100)*100
1510 IF LA=1 AND NLA<>11 THEN SUF$="st":RETURN
1520 IF LA=2 AND NLA<>12 THEN SUF$="nd":RETURN
1530 IF LA=3 AND NLA<>13 THEN SUF$="rd":RETURN
1540 SUF$="th"
1550 RETURN
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">Procedure.s Suffix(n.i)
Select n%10
Case 1 : If n%100<>11 : ProcedureReturn "st" : EndIf
Case 2 : If n%100<>12 : ProcedureReturn "nd" : EndIf
Case 3 : If n%100<>13 : ProcedureReturn "rd" : EndIf
EndSelect
ProcedureReturn "th"
EndProcedure
 
Procedure put(a.i,b.i)
For i=a To b : Print(Str(i)+Suffix(i)+" ") : Next
PrintN("")
EndProcedure
 
If OpenConsole()=0 : End 1 : EndIf
put(0,25)
put(250,265)
put(1000,1025)
Input()</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th </pre>
 
==={{header|QBasic}}===
<langsyntaxhighlight lang="basic">
DECLARE FUNCTION sufijo$ (n%)
DECLARE SUB imprimeOrdinal (loLim%, hiLim%)
Line 738 ⟶ 1,294:
END IF
END FUNCTION
</syntaxhighlight>
</lang>
 
==={{header|Run BASIC}}===
The [[#Liberty_BASIC|Liberty BASIC]] solution works without any changes.
 
==={{header|Sinclair ZX81 BASIC}}===
Works flawlessly with 2k or more of RAM. With 1k, the subroutine itself works but you can't quite print all the tests: the program crashes with an 'out of memory' error code after 1017th. (A slightly less useful and readable version gets as far as 1023rd; 1025th is probably attainable, but might involve obfuscating the program more than is appropriate for this site.)
<syntaxhighlight lang="basic"> 10 FOR N=0 TO 25
20 GOSUB 160
30 PRINT N$;" ";
40 NEXT N
50 PRINT
60 FOR N=250 TO 265
70 GOSUB 160
80 PRINT N$;" ";
90 NEXT N
100 PRINT
110 FOR N=1000 TO 1025
120 GOSUB 160
130 PRINT N$;" ";
140 NEXT N
150 STOP
160 LET N$=STR$ N
170 LET S$="TH"
180 IF LEN N$=1 THEN GOTO 200
190 IF N$(LEN N$-1)="1" THEN GOTO 230
200 IF N$(LEN N$)="1" THEN LET S$="ST"
210 IF N$(LEN N$)="2" THEN LET S$="ND"
220 IF N$(LEN N$)="3" THEN LET S$="RD"
230 LET N$=N$+S$
240 RETURN</syntaxhighlight>
{{out}}
<pre>
0TH 1ST 2ND 3RD 4TH 5TH 6TH 7TH 8TH 9TH 10TH 11TH 12TH 13TH 14TH 15TH 16TH 17TH 18TH 19TH 20TH 21ST 22ND 23RD 24TH 25TH
250TH 251ST 252ND 253RD 254TH 255TH 256TH 257TH 258TH 259TH 260TH 261ST 262ND 263RD 264TH 265TH
1000TH 1001ST 1002ND 1003RD 1004TH 1005TH 1006TH 1007TH 1008TH 1009TH 1010TH 1011TH 1012TH 1013TH 1014TH 1015TH 1016TH 1017TH 1018TH 1019TH 1020TH 1021ST 1022ND 1023RD 1024TH 1025TH</pre>
 
==={{header|True BASIC}}===
<syntaxhighlight lang="basic">
SUB sufijo (n)
LET n = INT(n)
LET NMod10 = MOD(n, 10)
LET NMod100 = MOD(n, 100)
IF (NMod10 = 1) AND (NMod100 <> 11) THEN
LET sufi$ = "st"
ELSE
IF (NMod10 = 2) AND (NMod100 <> 12) THEN
LET sufi$ = "nd"
ELSE
IF (NMod10 = 3) AND (NMod100 <> 13) THEN
LET sufi$ = "rd"
ELSE
LET sufi$ = "th"
END IF
END IF
END IF
PRINT sufi$;
END SUB
 
SUB imprimeOrdinal (loLim, hiLim)
LET loLim = INT(loLim)
LET hiLim = INT(hiLim)
FOR i = loLim TO hiLim
PRINT i;
CALL sufijo (i)
PRINT " ";
NEXT i
PRINT
END SUB
 
CALL imprimeOrdinal (0, 25)
CALL imprimeOrdinal (250, 265)
CALL imprimeOrdinal (1000, 1025)
END
</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="text">For x = 0 to 25 ' Test range 0..25
Push x : GoSub _PrintOrdinal
Next x : Print
 
For x = 250 to 265 ' Test range 250..265
Push x : GoSub _PrintOrdinal
Next x : Print
 
For x = 1000 to 1025 ' Test range 1000..1025
Push x : GoSub _PrintOrdinal
Next x : Print
 
End ' End test program
' ( n --)
_PrintOrdinal ' Ordinal subroutine
If Tos() > -1 Then ' If within range then
Print Using "____#";Tos();"'"; ' Print the number
' Take care of 11, 12 and 13
If (Tos()%100 > 10) * (Tos()%100 < 14) Then
Gosub (Pop() * 0) + 100 ' Clear stack and print "th"
Return ' We're done here
EndIf
 
Push Pop() % 10 ' Calculate n mod 10
GoSub 100 + 10 * ((Tos()>0) + (Tos()>1) + (Tos()>2) - (3 * (Pop()>3)))
Else ' And decide which ordinal to use
Print Pop();" is less than zero" ' Otherwise, it is an error
EndIf
 
Return
' Select and print proper ordinal
100 Print "th"; : Return
110 Print "st"; : Return
120 Print "nd"; : Return
130 Print "rd"; : Return</syntaxhighlight>
{{out}}
<pre>
0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 25'th
250'th 251'st 252'nd 253'rd 254'th 255'th 256'th 257'th 258'th 259'th 260'th 261'st 262'nd 263'rd 264'th 265'th
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th 1025'th
</pre>
 
==={{header|VBA}}===
{{trans|Phix}}<syntaxhighlight lang="vb">Private Function ordinals() As Variant
ordinals = [{"th","st","nd","rd"}]
End Function
 
Private Function Nth(n As Variant, Optional apostrophe As Boolean = False) As String
Dim mod10 As Integer: mod10 = n Mod 10 + 1
If mod10 > 4 Or n Mod 100 = mod10 + 9 Then mod10 = 1
Nth = CStr(n) & String$(Val(-apostrophe), "'") & ordinals()(mod10)
End Function
 
Public Sub main()
Ranges = [{0,25;250,265;1000,1025}]
For i = 1 To UBound(Ranges)
For j = Ranges(i, 1) To Ranges(i, 2)
If j Mod 10 = 0 Then Debug.Print
Debug.Print Format(Nth(j, i = 2), "@@@@@@@");
Next j
Debug.Print
Next i
End Sub</syntaxhighlight>{{out}}
<pre> 0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
10th 11th 12th 13th 14th 15th 16th 17th 18th 19th
20th 21st 22nd 23rd 24th 25th
 
250'th 251'st 252'nd 253'rd 254'th 255'th 256'th 257'th 258'th 259'th
260'th 261'st 262'nd 263'rd 264'th 265'th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
==={{header|XBasic}}===
{{trans|Ada}}
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">
PROGRAM "nth"
VERSION "0.0002"
 
DECLARE FUNCTION Entry()
INTERNAL FUNCTION Suffix$(n&&)
INTERNAL FUNCTION PrintImages (loLim&&, hiLim&&)
 
FUNCTION Entry()
PrintImages( 0, 25)
PrintImages( 250, 265)
PrintImages(1000, 1025)
END FUNCTION
 
FUNCTION Suffix$(n&&)
nMod10@@ = n&& MOD 10
nMod100@@ = n&& MOD 100
SELECT CASE TRUE
CASE (nMod10@@ = 1) AND (nMod100@@ <> 11):
RETURN ("st")
CASE (nMod10@@ = 2) AND (nMod100@@ <> 12):
RETURN ("nd")
CASE (nMod10@@ = 3) AND (nMod100@@ <> 13):
RETURN ("rd")
CASE ELSE:
RETURN ("th")
END SELECT
END FUNCTION
 
FUNCTION PrintImages(loLim&&, hiLim&&)
FOR i&& = loLim&& TO hiLim&&
PRINT TRIM$(STRING$(i&&)); Suffix$(i&&); " ";
NEXT
PRINT
END FUNCTION
END PROGRAM
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
==={{header|Yabasic}}===
{{trans|Liberty BASIC}}
<syntaxhighlight lang="xbasic">
sub ordinal$ (n)
NMod10 = mod(n, 10)
NMod100 = mod(n, 100)
if (NMod10 = 1) and (NMod100 <> 11) then
return "st"
else
if (NMod10 = 2) and (NMod100 <> 12) then
return "nd"
else
if (NMod10 = 3) and (NMod100 <> 13) then
return "rd"
else
return "th"
end if
end if
end if
end sub
 
sub imprimeOrdinal(a, b)
for i = a to b
print i, ordinal$(i), " ";
next i
print
end sub
 
imprimeOrdinal (0, 25)
imprimeOrdinal (250, 265)
imprimeOrdinal (1000, 1025)
end
</syntaxhighlight>
 
==={{header|ZX Spectrum Basic}}===
<syntaxhighlight lang="basic"> 10 FOR n=0 TO 25
20 GO SUB 140
30 PRINT n$;" ";
40 NEXT n
50 FOR n=250 TO 265
60 GO SUB 140
70 PRINT n$;" ";
80 NEXT n
90 FOR n=1000 TO 1025
100 GO SUB 140
110 PRINT n$;" ";
120 NEXT n
130 STOP
140 LET s$="th"
150 LET n$=STR$ n
160 IF LEN n$=1 THEN GO TO 180
170 IF n$(LEN n$-1)="1" THEN GO TO 210
180 IF n$(LEN n$)="1" THEN LET s$="st"
190 IF n$(LEN n$)="2" THEN LET s$="nd"
200 IF n$(LEN n$)="3" THEN LET s$="rd"
210 LET n$=n$+s$
220 RETURN</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th 1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">@echo off
::Main thing...
call :Nth 0 25
Line 753 ⟶ 1,565:
setlocal enabledelayedexpansion
for /l %%n in (%~1,1,%~2) do (
set curr_num=%%n
if !curr_num:~-2!==11 (set "out=%%nth"
) else if !curr_num:~-12!==112 (set "out=%%nstnth")
) else if !curr_num:~-12!==213 (set "out=%%nndnth")
) else if !curr_num:~-1!==31 (set "out=%%nrdnst")
) else if !curr_num:~-1!==2 (set "out=%%nnd"
set "range_output=!range_output! !out!"
) else if !curr_num:~-1!==3 (set "out=%%nrd"
) else (set "out=%%nth")
set "range_output=!range_output! !out!"
)
echo."!range_output:~1!"
goto :EOF</langsyntaxhighlight>
{{Out}}
<pre>
<pre>"0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11st 12nd 13rd 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th"
"0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th"
"250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th"
"1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011st1011th 1012nd1012th 1013rd1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th"
Press any key to continue . . .</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<lang bbcbasic> PROCNth( 0, 25)
PROCNth( 250, 265)
PROCNth(1000,1025)
END
 
DEF PROCNth(s%,e%)
LOCAL i%,suff$
FOR i%=s% TO e%
suff$="th"
IF i% MOD 10 = 1 AND i% MOD 100 <> 11 suff$="st"
IF i% MOD 10 = 2 AND i% MOD 100 <> 12 suff$="nd"
IF i% MOD 10 = 3 AND i% MOD 100 <> 13 suff$="rd"
PRINT STR$i%+suff$+" ";
NEXT
PRINT
ENDPROC</lang>
 
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
// Generate ASCII string of number n with ordinal suffix
Line 833 ⟶ 1,625:
for i = 250 to 265 do writef("%S*N", nth(i, buf))
for i = 1000 to 1025 do writef("%S*N", nth(i, buf))
$)</langsyntaxhighlight>
{{out}}
<pre style="height:50ex">0th
Line 906 ⟶ 1,698:
The bottom section of code contains the "subroutine" that calculates the ordinal of a given number; the top section generates the list of values to test.
 
<langsyntaxhighlight lang="befunge">0>55*:>1-\:0\`!v
#v$#$<^:\+*8"}"_
>35*:>1-\:0\`!v
Line 917 ⟶ 1,709:
htdd >$>:#,_$:vg
v"d"\*!`3:%+55<9
>%55+/1-!!*:8g,^</langsyntaxhighlight>
 
{{out}}
Line 923 ⟶ 1,715:
 
=={{header|BQN}}==
<langsyntaxhighlight lang="bqn">Nth ← {
sfx ← ⟨"th","st","nd","rd"⟩
(•Fmt 𝕩)∾sfx⊑˜ (1≠10|⌊𝕩÷10)×(3≥10|𝕩)×10|𝕩
}
 
∘‿4⥊ Nth¨ (↕26) ∾ (250+↕16) ∾ (1000+↕26)</langsyntaxhighlight>
{{out}}
<pre>┌─
Line 950 ⟶ 1,742:
┘</pre>
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
char* addSuffix(int num, char* buf, size_t len)
Line 1,001 ⟶ 1,793:
 
return 0;
}</langsyntaxhighlight>
Another method with dynamic memory allocation
<langsyntaxhighlight lang="c">#include <stdlib.h>
#include <stdio.h>
 
Line 1,035 ⟶ 1,827:
print_range(250, 265);
print_range(1000, 1025);
}</langsyntaxhighlight>
{{out}}
<pre>Set [0,25] :
Line 1,046 ⟶ 1,838:
=={{header|C sharp|C#}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="csharp">using System;
using System.Linq;
 
Line 1,077 ⟶ 1,869:
Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
}
}</langsyntaxhighlight>
Dotnet 5 version without LINQ
<langsyntaxhighlight lang="csharp">using System;
 
static string Ordinalize(int i)
Line 1,100 ⟶ 1,892:
PrintRange(0, 25);
PrintRange(250, 265);
PrintRange(1000, 1025);</langsyntaxhighlight>
 
{{Out}}
Line 1,108 ⟶ 1,900:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <string>
#include <iostream>
 
Line 1,148 ⟶ 1,940:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>Set [0,25] :
Line 1,158 ⟶ 1,950:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">
(defn n-th [n]
(str n
Line 1,173 ⟶ 1,965:
(apply str (interpose " " (map n-th (range 250 266))))
(apply str (interpose " " (map n-th (range 1000 1026))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,184 ⟶ 1,976:
 
Alternatively, if you want to print the full ordinal English, it becomes trivial with pprint:
<langsyntaxhighlight lang="clojure">
(apply str (interpose " " (map #(clojure.pprint/cl-format nil "~:R" %) (range 0 26))))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,193 ⟶ 1,985:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">nth = proc (n: int) returns (string)
num: string := int$unparse(n)
sfx: array[string] := array[string]$[0: "th", "st", "nd", "rd"]
Line 1,223 ⟶ 2,015:
do_range(250,265)
do_range(1000,1025)
end start_up</langsyntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
Line 1,238 ⟶ 2,030:
=={{header|COBOL}}==
COBOL stores numbers in decimal form, so there is no need to use a modulo function: the last digit or the last two digits can be extracted directly.
<langsyntaxhighlight lang="cobol">IDENTIFICATION DIVISION.
PROGRAM-ID. NTH-PROGRAM.
DATA DIVISION.
Line 1,268 ⟶ 2,060:
IF LAST-DIGIT IS EQUAL TO 1 THEN MOVE 'ST' TO SUFFIX.
IF LAST-DIGIT IS EQUAL TO 2 THEN MOVE 'ND' TO SUFFIX.
IF LAST-DIGIT IS EQUAL TO 3 THEN MOVE 'RD' TO SUFFIX.</langsyntaxhighlight>
Output:
<pre> 0TH 1ST 2ND 3RD 4TH 5TH 6TH 7TH 8TH 9TH 10TH 11TH 12TH 13TH 14TH 15TH 16TH 17TH 18TH 19TH 20TH 21ST 22ND 23RD 24TH 25TH 250TH 251ST 252ND 253RD 254TH 255TH 256TH 257TH 258TH 259TH 260TH 261ST 262ND 263RD 264TH 265TH 1000TH 1001ST 1002ND 1003RD 1004TH 1005TH 1006TH 1007TH 1008TH 1009TH 1010TH 1011TH 1012TH 1013TH 1014TH 1015TH 1016TH 1017TH 1018TH 1019TH 1020TH 1021ST 1022ND 1023RD 1024TH 1025TH</pre>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">(defun add-suffix (number)
(let* ((suffixes #10("th" "st" "nd" "rd" "th"))
(last2 (mod number 100))
Line 1,281 ⟶ 2,073:
(svref suffixes last-digit))))
(format nil "~a~a" number suffix)))
</syntaxhighlight>
</lang>
 
 
A more concise, albeit less readable version:
<langsyntaxhighlight lang="lisp">(defun add-suffix (n)
(format nil "~d'~:[~[th~;st~;nd~;rd~:;th~]~;th~]" n (< (mod (- n 10) 100) 10) (mod n 10)))
</syntaxhighlight>
</lang>
 
 
Display the results:
<langsyntaxhighlight lang="lisp">(loop for (low high) in '((0 25) (250 265) (1000 1025))
do (progn
(format t "~a to ~a: " low high)
(loop for n from low to high
do (format t "~a " (add-suffix n))
finally (terpri))))</langsyntaxhighlight>
 
{{Out}}
Line 1,304 ⟶ 2,096:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
include "strings.coh";
 
Line 1,343 ⟶ 2,135:
test(0, 25);
test(250,265);
test(1000,1025);</langsyntaxhighlight>
 
{{out}}
Line 1,358 ⟶ 2,150:
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">struct Int
def ordinalize
num = self.abs
Line 1,376 ⟶ 2,168:
[(0..25),(250..265),(1000..1025)].each{|r| puts r.map{ |n| n.ordinalize }.join(", "); puts}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,388 ⟶ 2,180:
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang="d">import std.stdio, std.string, std.range, std.algorithm;
 
string nth(in uint n) pure {
Line 1,399 ⟶ 2,191:
foreach (r; [iota(26), iota(250, 266), iota(1000, 1026)])
writefln("%-(%s %)", r.map!nth);
}</langsyntaxhighlight>
{{out}}
<pre>0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 25'th
Line 1,407 ⟶ 2,199:
=={{header|Delphi}}==
See [https://www.rosettacode.org/wiki/N%27th#Pascal Pascal].
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc nonrec nth(word n; *char buf) *char:
channel output text ch;
open(ch, buf);
write(ch; n,
if (n/10)%10=1 then "th"
elif n%10=1 then "st"
elif n%10=2 then "nd"
elif n%10=3 then "rd"
else "th"
fi
);
close(ch);
buf
corp;
 
proc nonrec print_range(word start, stop) void:
[8] char buf;
word col, n;
col := 0;
for n from start upto stop do
write(nth(n, &buf[0]));
col := col + 1;
if col%10=0 then writeln() else write('\t') fi
od;
writeln()
corp
 
proc nonrec main() void:
print_range(0, 25);
print_range(250, 265);
print_range(1000, 1025)
corp</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
10th 11th 12th 13th 14th 15th 16th 17th 18th 19th
20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th
260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func$ nth num .
last2 = num mod 100
last = num mod 10
if last2 >= 11 and last2 <= 13
return num & "th"
elif last = 1
return num & "st"
elif last = 2
return num & "nd"
elif last = 3
return num & "rd"
else
return num & "th"
.
.
print "0 to 25:"
for i = 0 to 25
write nth i & " "
.
print ""
print "250 to 265:"
for i = 250 to 265
write nth i & " "
.
print ""
print "1000 to 1025:"
for i = 1000 to 1025
write nth i & " "
.
</syntaxhighlight>
{{out}}
<pre>
0 to 25:
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250 to 265:
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000 to 1025:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Elena}}==
{{trans|C#}}
ELENA 56.0x :
<langsyntaxhighlight lang="elena">import extensions;
import system'math;
import system'routines;
Line 1,420 ⟶ 2,297:
{
int i := self.Absolute;
if (new int[]{11,12,13}.ifExists(i.mod:(100)))
{
^ i.toPrintable() + "th"
Line 1,439 ⟶ 2,316:
console.printLine(new Range(250,26).selectBy(mssgconst ordinalize<op>[1]));
console.printLine(new Range(1000,26).selectBy(mssgconst ordinalize<op>[1]))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,448 ⟶ 2,325:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule RC do
def ordinalize(n) do
num = abs(n)
Line 1,467 ⟶ 2,344:
Enum.each([0..25, 250..265, 1000..1025], fn range ->
Enum.map(range, fn n -> RC.ordinalize(n) end) |> Enum.join(" ") |> IO.puts
end)</langsyntaxhighlight>
 
{{out}}
Line 1,477 ⟶ 2,354:
 
=={{header|ERRE}}==
<syntaxhighlight lang="erre">
<lang ERRE>
PROGRAM NTH_SOLVE
 
Line 1,501 ⟶ 2,378:
NTH(1000,1025)
END PROGRAM
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,514 ⟶ 2,391:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">open System
 
let ordinalsuffix n =
Line 1,529 ⟶ 2,406:
[1000..1025] |> show
0
</syntaxhighlight>
</lang>
{{out}}
<pre> 0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 1,536 ⟶ 2,413:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: io kernel math math.order math.parser math.ranges qw
sequences ;
IN: rosetta-code.nth
Line 1,549 ⟶ 2,426:
[ [ n'th write bl ] each nl ] tri@ ;
 
MAIN: n'th-demo</langsyntaxhighlight>
{{out}}
<pre>
Line 1,556 ⟶ 2,433:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Fennel}}==
{{trans|Lua}}
 
<syntaxhighlight lang="fennel">
(fn get-suffix [n]
(let [last-two (% n 100)
last-one (% n 10)]
(if (and (> last-two 3) (< last-two 21)) :th
(= last-one 1) :st
(= last-one 2) :nd
(= last-one 3) :rd
:th)))
 
(fn nth [n]
(.. n "'" (get-suffix n)))
 
(for [i 0 25]
(print (nth i) (nth (+ i 250)) (nth (+ i 1000))))
</syntaxhighlight>
 
{{out}}
Same as [[#Lua|Lua]].
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: 'nth ( -- c-addr ) s" th st nd rd th th th th th th " drop ;
: .nth ( n -- )
dup 100 mod 10 20 within if 0 .r ." th " exit then
dup 0 .r 10 mod 3 * 'nth + 3 type ;
 
Line 1,567 ⟶ 2,467:
26 0 test 266 250 test 1026 1000 test ;
 
tests</langsyntaxhighlight>
 
{{out}}
Line 1,584 ⟶ 2,484:
1000th 1001st 1002nd 1003rd 1004th
1005th 1006th 1007th 1008th 1009th
1010th 1011st1011th 1012nd1012th 1013rd1013th 1014th
1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th
1024th1022th ok</pre>
 
=={{header|Fortran}}==
Line 1,598 ⟶ 2,498:
 
Please find the compilation instructions and examples in comments at the start of the source.
<langsyntaxhighlight Fortranlang="fortran">!-*- mode: compilation; default-directory: "/tmp/" -*-
!Compilation started at Fri Jun 6 15:40:18
!
Line 1,688 ⟶ 2,588:
end function ordinate
 
end program nth</langsyntaxhighlight>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
' Apostrophes NOT used as incorrect English
 
Function ordinal(n As UInteger) As String
Dim ns As String = Str(n)
Select Case Right(ns, 1)
Case "0", "4" To "9"
Return ns + "th"
Case "1"
If Right(ns, 2) = "11" Then Return ns + "th"
Return ns + "st"
Case "2"
If Right(ns, 2) = "12" Then Return ns + "th"
Return ns + "nd"
Case "3"
If Right(ns, 2) = "13" Then Return ns + "th"
Return ns + "rd"
End Select
End Function
 
Dim i As Integer
For i = 0 To 25
Print ordinal(i); " ";
Next
Print : Print
 
For i = 250 To 265
Print ordinal(i); " ";
Next
Print : Print
 
For i = 1000 To 1025
Print ordinal(i); " ";
Next
Print : Print
 
Print "Press any key to quit"
Sleep</lang>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th
1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=6d60749ae886a37f128e75cffc6c7118 Click this link to run this code]'''
<lang gambas>Public Sub Main()
Dim siNums As Short[] = [0, 25, 250, 265, 1000, 1025]
Dim siCount, siNumbers As Short
Dim sOrdinal As String
 
For siNumbers = 0 To 4 Step 2
For siCount = siNums[siNumbers] To siNums[siNumbers + 1]
sOrdinal = "th"
If Right(Str(siCount), 1) = "1" And Right(Str(siCount), 2) <> "11" Then sOrdinal = "st"
If Right(Str(siCount), 1) = "2" And Right(Str(siCount), 2) <> "12" Then sOrdinal = "nd"
If Right(Str(siCount), 1) = "3" And Right(Str(siCount), 2) <> "13" Then sOrdinal = "rd"
Print siCount & sOrdinal;;
Next
Print gb.NewLine
Next
 
End </lang>
Output:
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Go}}==
{{trans|Raku}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,804 ⟶ 2,628:
}
fmt.Println()
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,810 ⟶ 2,634:
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|GW-BASIC}}==
{{trans|Ada}}
{{works with|PC-BASIC|any}}
<lang qbasic>
10 ' N'th
20 LET LOLIM% = 0
30 LET HILIM% = 25
40 GOSUB 1000
50 LET LOLIM% = 250
60 LET HILIM% = 265
70 GOSUB 1000
80 LET LOLIM% = 1000
90 LET HILIM% = 1025
100 GOSUB 1000
110 END
995 ' Print images
1000 FOR I% = LOLIM% TO HILIM%
1010 LET NR% = I%
1020 GOSUB 1500
1030 LET SI$ = STR$(I%)
1040 PRINT RIGHT$(SI$, LEN(SI$) - 1); SUF$; " ";
1050 NEXT I%
1060 PRINT
1070 RETURN
 
1495 ' Get suffix
1500 IF (NR% MOD 10 = 1) AND (NR% MOD 100 <> 11) THEN LET SUF$ = "st": GOTO 2000
1600 IF (NR% MOD 10 = 2) AND (NR% MOD 100 <> 12) THEN LET SUF$ = "nd": GOTO 2000
1700 IF (NR% MOD 10 = 3) AND (NR% MOD 100 <> 13) THEN LET SUF$ = "rd": GOTO 2000
1800 LET SUF$ = "th"
2000 RETURN
</lang>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Array
 
ordSuffs :: Array Integer String
Line 1,871 ⟶ 2,655:
printOrdSuffs [ 0.. 25]
printOrdSuffs [ 250.. 265]
printOrdSuffs [1000..1025]</langsyntaxhighlight>
{{out}}
<pre>
Line 1,882 ⟶ 2,666:
 
The following works in both languages.
<langsyntaxhighlight lang="unicon">procedure main(A)
every writes(" ",nth(0 to 25) | "\n")
every writes(" ",nth(250 to 265) | "\n")
Line 1,892 ⟶ 2,676:
(n%10 = 2, n%100 ~= 12, "nd") |
(n%10 = 3, n%100 ~= 13, "rd") | "th")
end</langsyntaxhighlight>
 
{{out}}
Line 1,901 ⟶ 2,685:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013h 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
->
</pre>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(function ordinal n
(if ([11 12 13] (rem n 100))
(str n "th")
(str n (or ((rem n 10) ["th" "st" "nd" "rd"]) "th"))))
 
(function line x y
(-> (range x y)
(map (comp ordinal (pad-left " " 6)))
(join " ")))
 
(.. str (line 0 13) "\n" (line 1000 1013)
"\n\n" (line 13 26) "\n" (line 1013 1026)
"\n\n" (line 250 266))
</syntaxhighlight>
 
{{out}}
 
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th
 
13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
</pre>
 
Line 1,907 ⟶ 2,721:
Implementation:
 
<langsyntaxhighlight Jlang="j">suf=: (;:'th st nd rd th') {::~ 4 <. 10 10 (* 1&~:)~/@#: ]
nth=: [: ;:inv (": , suf)each</langsyntaxhighlight>
 
Task:
 
<langsyntaxhighlight Jlang="j"> thru=: <./ + i.@(+ *)@-~
nth 0 thru 25
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 1,918 ⟶ 2,732:
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
nth 1000 thru 1025
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class Nth {
public static String ordinalAbbrev(int n){
String ans = "th"; //most of the time it should be "th"
Line 1,946 ⟶ 2,760:
}
}
}</langsyntaxhighlight>
{{works with|Java|8+}}
<langsyntaxhighlight lang="java">package nth;
 
import java.util.stream.IntStream;
Line 1,995 ⟶ 2,809:
;
}
}</langsyntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 2,005 ⟶ 2,819:
===ES5===
 
<langsyntaxhighlight JavaScriptlang="javascript">console.log(function () {
 
var lstSuffix = 'th st nd rd th th th th th th'.split(' '),
Line 2,028 ⟶ 2,842:
}).join('\n\n');
}());</langsyntaxhighlight>
 
 
{{Out}}
 
<langsyntaxhighlight JavaScriptlang="javascript">0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</langsyntaxhighlight>
 
 
===ES6===
 
<langsyntaxhighlight JavaScriptlang="javascript">(function (lstTestRanges) {
'use strict'
 
Line 2,067 ⟶ 2,881:
);
 
})([[0, 25], [250, 265], [1000, 1025]]);</langsyntaxhighlight>
 
 
Line 2,080 ⟶ 2,894:
"1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th",
"1021st", "1022nd", "1023rd", "1024th", "1025th"]]</pre>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE
suffix == abs 89 + 100 rem 9 - 10 rem [{1 2 3} in] [] [pop 0] ifte ["th" "st" "nd" "rd"] of;
nth == ['d 1 1 format] [suffix] cleave concat.
 
[0 250 1000] [25 [dup nth putchars ' putch succ] times nth putchars '\n putch] step.</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th 266th 267th 268th 269th 270th 271st 272nd 273rd 274th 275th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|jq}}==
<syntaxhighlight lang="jq">
<lang jq>
# ordinalize an integer input, positive or negative
def ordinalize:
Line 2,100 ⟶ 2,925:
([range(-5; -1)], [range(0;26)], [range(250;266)], [range(1000;1026)])
| map(ordinalize)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,110 ⟶ 2,935:
 
=={{header|Julia}}==
<syntaxhighlight lang ="julia">using Printf</langsyntaxhighlight>
'''Function''':
<langsyntaxhighlight lang="julia">function ordinal(n::Integer)
n < 0 && throw(DomainError())
suffixes = ("st", "nd", "rd")
Line 2,123 ⟶ 2,948:
end
return string(n, suf)
end</langsyntaxhighlight>
 
'''Main''':
<langsyntaxhighlight lang="julia">println("Tests of ordinal formatting of integers.")
for (i, n) in enumerate(0:25)
(i - 1) % 10 == 0 && println()
Line 2,142 ⟶ 2,967:
(i - 1) % 10 == 0 && println()
@printf("%7s", ordinal(n))
end</langsyntaxhighlight>
'''Main2''':
<langsyntaxhighlight lang="julia">Nth(x::Integer) = if x % 100 ∈ [11, 12, 13] "th" else ["th", "st", "nd", "rd", "th"][min(x % 10 + 1, 5)] end
NthA(x::Integer) = "$(x)'$(Nth(x)) "
[0:25..., 250:265..., 1000:1025...] .|> NthA .|> print;</langsyntaxhighlight>
 
{{out}}
Line 2,163 ⟶ 2,988:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">fun Int.ordinalAbbrev() =
if (this % 100 / 10 == 1) "th"
else when (this % 10) { 1 -> "st" 2 -> "nd" 3 -> "rd" else -> "th" }
Line 2,171 ⟶ 2,996:
fun main(args: Array<String>) {
listOf((0..25), (250..265), (1000..1025)).forEach { println(it.ordinalAbbrev()) }
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
Translation from the javascript entry
<langsyntaxhighlight lang="scheme">
{def fnOrdinalForm
{lambda {:n}
Line 2,195 ⟶ 3,020:
1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th
1021st 1022nd 1023rd 1024th 1025th
</syntaxhighlight>
</lang>
 
=={{header|Liberty BASIC}}==
{{trans|Ada}}
{{works with|Just BASIC|any}}
<lang lb>
call printImages 0, 25
call printImages 250, 265
call printImages 1000, 1025
end
 
sub printImages loLim, hiLim
loLim = int(loLim)
hiLIm = int(hiLim)
for i = loLim to hiLim
print str$(i) + suffix$(i) + " ";
next i
print
end sub
 
function suffix$(n)
n = int(n)
nMod10 = n mod 10
nMod100 = n mod 100
if (nMod10 = 1) and (nMod100 <> 11) then
suffix$ = "st"
else
if (nMod10 = 2) and (nMod100 <> 12) then
suffix$ = "nd"
else
if (NMod10 = 3) and (NMod100 <> 13) then
suffix$ = "rd"
else
suffix$ = "th"
end if
end if
end if
end function
</lang>
{{out}}
<pre>
0th 1st 2nd 3th 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23th 24th 25th
250th 251st 252nd 253th 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263th 264th 265th
1000th 1001st 1002nd 1003th 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023th 1024th 1025th
</pre>
 
=={{header|Lua}}==
The apostrophe just looks weird if you ask me. No one did, obviously.
<langsyntaxhighlight Lualang="lua">function getSuffix (n)
local lastTwo, lastOne = n % 100, n % 10
if lastTwo > 3 and lastTwo < 21 then return "th" end
Line 2,254 ⟶ 3,035:
function Nth (n) return n .. "'" .. getSuffix(n) end
for i = 0, 25 do print(Nth(i), Nth(i + 250), Nth(i + 1000)) end</langsyntaxhighlight>
 
{{out}}
Line 2,287 ⟶ 3,068:
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">toOrdinal := proc(n:: nonnegint)
if 1 <= n and n <= 10 then
if n >= 4 then
Line 2,311 ⟶ 3,092:
end do;
printf("\n\n");
end do;</langsyntaxhighlight>
{{out}}
<pre>
Line 2,323 ⟶ 3,104:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
I borrowed the logic from the Python code.
<langsyntaxhighlight Mathematicalang="mathematica">suffixlist = {"th", "st", "nd", "rd", "th", "th", "th", "th", "th","th"};
addsuffix[n_] := Module[{suffix},
suffix = Which[
Line 2,334 ⟶ 3,115:
addsuffix[#] & /@ Range[0, 25] (* test 1 *)
addsuffix[#] & /@ Range[250, 265] (* test 2 *)
addsuffix[#] & /@ Range[1000, 1025] (* test 3 *)</langsyntaxhighlight>
{{out}}
<pre>{"0th", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th"}
Line 2,343 ⟶ 3,124:
 
=={{header|MATLAB}}==
<langsyntaxhighlight MATLABlang="matlab">function s = nth(n)
tens = mod(n, 100);
if tens > 9 && tens < 20
Line 2,360 ⟶ 3,141:
end
s = sprintf('%d%s', n, suf);
end</langsyntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 2,366 ⟶ 3,147:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Microsoft Small Basic}}==
{{trans|Ada}}
<lang microsoftsmallbasic>
loLim = 0
hiLim = 25
PrintImages()
loLim = 250
hiLim = 265
PrintImages()
loLim = 1000
hiLim = 1025
PrintImages()
Sub PrintImages
For i = loLim To hiLim
nr = i
GetSuffix()
TextWindow.Write(i + suffix + " ")
EndFor
TextWindow.WriteLine("")
EndSub
Sub GetSuffix
rem10 = Math.Remainder(nr, 10)
rem100 = Math.Remainder(nr, 100)
If rem10 = 1 And rem100 <> 11 Then
suffix = "st"
ElseIf rem10 = 2 And rem100 <> 12 Then
suffix = "nd"
ElseIf rem10 = 3 And rem100 <> 13 Then
suffix = "rd"
Else
suffix = "th"
EndIf
EndSub
</lang>
 
=={{header|MiniScript}}==
To get the output all on one line, we append it to a list as we go, and then print the list all at once at the end.
 
<syntaxhighlight lang="miniscript">
<lang MiniScript>ordinal = function(n)
ordinal = function(n)
if n > 3 and n < 20 then return n + "th"
if n % 100 > 3 and n %100 < 20 then return n + "th"
if n % 10 == 1 then return n + "st"
if n % 10 == 2 then return n + "nd"
Line 2,415 ⟶ 3,160:
end function
 
out = []
test = function(from, to)
out = []
for i in range(from, to)
out.push ordinal(i)
end for
print out.join
end function
 
Line 2,425 ⟶ 3,171:
test 250, 265
test 1000, 1025
</syntaxhighlight>
print out.join</lang>
 
{{out}}
<pre>
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th 1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011st 1012nd 1013rd 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Modula-2}}==
{{trans|Ada}}
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<langsyntaxhighlight lang="modula2">
MODULE Nth;
 
Line 2,479 ⟶ 3,229:
PrintImages(1000, 1025);
END Nth.
</syntaxhighlight>
</lang>
 
=={{header|Nanoquery}}==
{{trans|Java}}
<langsyntaxhighlight lang="nanoquery">def ordinalAbbrev(n)
if int(n % 100 / 10) = 1
return "th"
Line 2,512 ⟶ 3,262:
print (i + "'" + ordinalAbbrev(i) + " ")
end
println</langsyntaxhighlight>
{{out}}
<pre>0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 25'th
Line 2,520 ⟶ 3,270:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">const Suffix = ["th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"]
 
proc nth(n: Natural): string =
Line 2,528 ⟶ 3,278:
for i in j..j+24:
stdout.write nth(i), " "
echo ""</langsyntaxhighlight>
{{out}}
<pre>0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th
Line 2,538 ⟶ 3,288:
=={{header|Objeck}}==
{{trans|Java}}
<langsyntaxhighlight lang="objeck">class Nth {
function : OrdinalAbbrev(n : Int ) ~ String {
ans := "th"; # most of the time it should be "th"
Line 2,572 ⟶ 3,322:
};
}
}</langsyntaxhighlight>
 
{{output}}
Line 2,583 ⟶ 3,333:
=={{header|OCaml}}==
 
<syntaxhighlight lang="ocaml">
<lang Ocaml>
let show_nth n =
if (n mod 10 = 1) && (n mod 100 <> 11) then "st"
Line 2,599 ⟶ 3,349:
 
List.iter show_ordinals [ (0,25); (250,265); (1000,1025) ]
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,610 ⟶ 3,360:
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">: nth(n)
| r |
n "th" over 10 mod ->r
Line 2,616 ⟶ 3,366:
r 2 == ifTrue: [ n 100 mod 12 == ifFalse: [ drop "nd" ] ]
r 3 == ifTrue: [ n 100 mod 13 == ifFalse: [ drop "rd" ] ]
+ ;</langsyntaxhighlight>
 
{{out}}
Line 2,637 ⟶ 3,387:
(Spurious apostrophes intentionally omitted, following Raku.)
 
<langsyntaxhighlight lang="parigp">ordinal(n)=my(k=n%10,m=n%100); Str(n,if(m<21&&m>3,"th",k==1,"st",k==2,"nd",k==3,"rd","th"));
apply(ordinal, [0..25])
apply(ordinal, [250..265])
apply(ordinal, [1000..1025])
apply(ordinal, [111, 1012])</langsyntaxhighlight>
{{out}}
<pre>%1 = ["0th", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st", "22nd", "23rd", "24th", "25th"]
Line 2,650 ⟶ 3,400:
=={{header|Pascal}}==
nearly copy of [[N'th#Ada|Ada]]
<langsyntaxhighlight lang="pascal">Program n_th;
 
function Suffix(N: NativeInt):AnsiString;
Line 2,682 ⟶ 3,432:
Print_Images( 250, 265);
Print_Images(1000, 1025);
end.</langsyntaxhighlight>
{{Out}} shortened
<pre>
Line 2,693 ⟶ 3,443:
{{Trans|Raku}}
Requires Perl 5.10 or newer for the Defined OR operator (//).
<langsyntaxhighlight lang="perl">use 5.10.0;
my %irregulars = ( 1 => 'st',
2 => 'nd',
Line 2,708 ⟶ 3,458:
 
sub range { join ' ', map { nth($_) } @{$_[0]} }
print range($_), "\n" for ([0..25], [250..265], [1000..1025]);</langsyntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 2,716 ⟶ 3,466:
Alternatively, can use a library.
{{libheader|Lingua&#58;&#58;EN&#58;&#58;Numbers&#58;&#58;Ordinate}}
<langsyntaxhighlight lang="perl">use Lingua::EN::Numbers::Ordinate 'ordinate';
foreach my $i (0..25, 250..265, 1000..1025) {
print ordinate($i),"\n";
}</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">ordinals</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"th"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"st"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"nd"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"rd"</span><span style="color: #0000FF;">}</span>
Line 2,739 ⟶ 3,489:
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,754 ⟶ 3,504:
</pre>
Alternatively you can use the builtin ord(), and a more functional style, as follows (same output)
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">do_one</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">pad_head</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d%s%s"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">apostrophe</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">ord</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)</span>
Line 2,763 ⟶ 3,513:
<span style="color: #008080;">constant</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">,</span><span style="color: #000000;">re</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">25</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">250</span><span style="color: #0000FF;">,</span><span style="color: #000000;">265</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1025</span><span style="color: #0000FF;">}})</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #000000;">do_set</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">re</span><span style="color: #0000FF;">,</span><span style="color: #000000;">rs</span><span style="color: #0000FF;">}),{</span><span style="color: #004600;">false</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #004600;">false</span><span style="color: #0000FF;">}})</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PHP}}==
<langsyntaxhighlight PHPlang="php">function nth($num) {
$os = "th";
if ($num % 100 <= 10 or $num % 100 > 20) {
Line 2,790 ⟶ 3,540:
}
echo "\n";
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,797 ⟶ 3,547:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Picat}}==
<code>nth/3</code> is a built-in predicate in Picat, so let's call the functions <code>nth2/1</code> and onward.
===Prolog style===
{{trans|Prolog}}
<syntaxhighlight lang="picat">nth2(N) = N.to_string() ++ Th =>
( tween(N) -> Th = "th"
; 1 = N mod 10 -> Th = "st"
; 2 = N mod 10 -> Th = "nd"
; 3 = N mod 10 -> Th = "rd"
; Th = "th" ).
tween(N) => Tween = N mod 100, between(11, 13, Tween).</syntaxhighlight>
 
===Function with explicit conditions===
<syntaxhighlight lang="picat">nth3(N) = cc(N,"th"), tween(N) => true.
nth3(N) = cc(N,"st"), N mod 10 = 1 => true.
nth3(N) = cc(N,"nd"), N mod 10 = 2 => true.
nth3(N) = cc(N,"rd"), N mod 10 = 3 => true.
nth3(N) = cc(N,"th") => true.
% helper function
cc(N,Th) = N.to_string() ++ Th.</syntaxhighlight>
 
===List of suffixes===
{{trans|Python}}
<syntaxhighlight lang="picat">nth4(N) = Nth =>
Suffix = ["th","st","nd","rd","th","th","th","th","th","th"],
Nth = N.to_string() ++ cond((N mod 100 <= 10; N mod 100 > 20), Suffix[1 + N mod 10], "th").</syntaxhighlight>
 
===Test===
<syntaxhighlight lang="picat">go =>
Ranges = [ 0..25, 250..265, 1000..1025],
foreach(Range in Ranges) println([nth2(I) : I in Range])
end,
nl.</syntaxhighlight>
 
{{out}}
<pre>[0th,1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,12th,13th,14th,15th,16th,17th,18th,19th,20th,21st,22nd,23rd,24th,25th]
[250th,251st,252nd,253rd,254th,255th,256th,257th,258th,259th,260th,261st,262nd,263rd,264th,265th]
[1000th,1001st,1002nd,1003rd,1004th,1005th,1006th,1007th,1008th,1009th,1010th,1011th,1012th,1013th,1014th,1015th,1016th,1017th,1018th,1019th,1020th,1021st,1022nd,1023rd,1024th,1025th]</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de rangeth (A B)
(mapcar
'((I)
Line 2,816 ⟶ 3,605:
(prinl (glue " " (rangeth 1000 1025)))
 
(bye)</langsyntaxhighlight>
{{out}}
<pre>
Line 2,825 ⟶ 3,614:
 
=={{header|PL/I}}==
<syntaxhighlight lang="text">Nth: procedure options (main); /* 1 June 2014 */
declare i fixed (10);
 
Line 2,850 ⟶ 3,639:
end enth;
 
end Nth;</langsyntaxhighlight>
{{out}}
<pre> 0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th
Line 2,861 ⟶ 3,650:
1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st
1022nd 1023rd 1024th 1025th</pre>
 
=={{header|PL/M}}==
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
The 8080 PL/M compiler doesn't recognise lower-case letters, so the letters for the suffixes have to be specified by their ASCII codes.
<syntaxhighlight lang="plm">
100H: /* SUFFIX NUMBERS WITH ST, ND, RD OR TH AS APPROPRIATE */
 
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
 
/* TASK */
 
DECLARE LD LITERALLY '100' /* LOWER CASE LETTERS NEEDED FOR THE SUFFICES */
, LH LITERALLY '104'
, LN LITERALLY '110'
, LR LITERALLY '114'
, LS LITERALLY '115'
, LT LITERALLY '116'
;
 
/* RETURNS THE TWO CHARACTER ORDINAL SUFFIX FOR N */
SUFFIX: PROCEDURE( N )ADDRESS;
DECLARE N ADDRESS;
DECLARE ( S1, S2 ) BYTE;
S1 = LT;
S2 = LH;
IF N MOD 100 < 4 OR N MOD 100 > 20 THEN DO;
DECLARE N10 ADDRESS;
N10 = N MOD 10;
IF N10 = 1 THEN DO;
S1 = LS;
S2 = LT;
END;
ELSE IF N10 = 2 THEN DO;
S1 = LN;
S2 = LD;
END;
ELSE IF N10 = 3 THEN DO;
S1 = LR;
S2 = LD;
END;
END;
RETURN ( S1 * 256 ) + S2;
END SUFFIX;
 
/* PRINTS THE TWO CHARACTER SUFFIX IN S */
PR$SUFFIX: PROCEDURE( S );
DECLARE S ADDRESS;
CALL PR$CHAR( HIGH( S ) );
CALL PR$CHAR( LOW( S ) );
END PR$SUFFIX ;
 
DECLARE I ADDRESS;
 
DO I = 0 TO 25;
IF I < 10 THEN CALL PR$CHAR( ' ' );
CALL PR$CHAR( ' ' );CALL PR$NUMBER( I );CALL PR$SUFFIX( SUFFIX( I ) );
IF ( I + 1 ) MOD 10 = 0 THEN CALL PR$NL;
END;
CALL PR$NL;
CALL PR$NL;
DO I = 250 TO 265;
CALL PR$CHAR( ' ' );CALL PR$NUMBER( I );CALL PR$SUFFIX( SUFFIX( I ) );
IF ( I - 249 ) MOD 10 = 0 THEN CALL PR$NL;
END;
CALL PR$NL;
CALL PR$NL;
DO I = 1000 TO 1025;
CALL PR$CHAR( ' ' );CALL PR$NUMBER( I );CALL PR$SUFFIX( SUFFIX( I ) );
IF ( I - 999 ) MOD 10 = 0 THEN CALL PR$NL;
END;
CALL PR$NL;
 
EOF
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
10th 11th 12th 13th 14th 15th 16th 17th 18th 19th
20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th
260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|PowerShell}}==
<syntaxhighlight lang ="powershell">function nth($inp){
function nth($inp){
$suffix = "th"
$suffix = "th"
 
switch($inp % 10100){
1 11{$suffix="stth"}
2 12{$suffix="ndth"}
3 13{$suffix="rdth"}
default{
}
switch($inp % 10){
return "$inp$suffix "
1{$suffix="st"}
2{$suffix="nd"}
3{$suffix="rd"}
}
}
}
return "$inp$suffix "
}
 
0..25 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
1000..1025 | %{Write-host -nonewline (nth "$_")};""</lang>
</syntaxhighlight>
{{Out}}
<pre>
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11st 12nd 13rd 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011st1011th 1012nd1012th 1013rd1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
</pre>
 
===An Alternate Version===
This is, I think, is a more "PowerShelly" way:
<syntaxhighlight lang="powershell">
<lang PowerShell>
function Get-Nth ([int]$Number)
{
$suffix = "th"
 
switch ($Number % 10100){
11 {$suffix = "th"}
{
112 {$suffix = "stth"}
213 {$suffix = "ndth"}
3default {$suffix = "rd"}
switch ($Number % 10){
1 {$suffix = "st"}
2 {$suffix = "nd"}
3 {$suffix = "rd"}
}
}
}
 
Line 2,902 ⟶ 3,811:
251..265 | ForEach-Object {Get-Nth $_} | Format-Wide {$_} -Column 5 -Force
1001..1025 | ForEach-Object {Get-Nth $_} | Format-Wide {$_} -Column 5 -Force
</syntaxhighlight>
</lang>
{{Out}}
<pre>
1st 2nd 3rd 4th 5th
6th 7th 8th 9th 10th
11st11th 12th 12nd 13rd 13th 14th 15th
16th 17th 18th 19th 20th
21st 22nd 23rd 24th 25th
 
 
251st 252nd 253rd 254th 255th
256th 257th 258th 259th 260th
261st 262nd 263rd 264th 265th
 
 
1001st 1002nd 1003rd 1004th 1005th
1006th 1007th 1008th 1009th 1010th
1011st1011th 1012th 1012nd 1013rd 1013th 1014th 1015th
1016th 1017th 1018th 1019th 1020th
1021st 1022nd 1023rd 1024th 1025th
</pre>
 
Line 2,929 ⟶ 3,838:
Following Icon:
 
<langsyntaxhighlight lang="prolog">nth(N, N_Th) :-
( tween(N) -> Th = "th"
; 1 is N mod 10 -> Th = "st"
Line 2,945 ⟶ 3,854:
nl, nl,
forall( between(1000,1025,N), (nth(N, N_Th), format('~w, ', N_Th)) ).
</syntaxhighlight>
</lang>
 
{{out}} of `test/0`:
Line 2,957 ⟶ 3,866:
true.
</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure.s Suffix(n.i)
Select n%10
Case 1 : If n%100<>11 : ProcedureReturn "st" : EndIf
Case 2 : If n%100<>12 : ProcedureReturn "nd" : EndIf
Case 3 : If n%100<>13 : ProcedureReturn "rd" : EndIf
EndSelect
ProcedureReturn "th"
EndProcedure
 
Procedure put(a.i,b.i)
For i=a To b : Print(Str(i)+Suffix(i)+" ") : Next
PrintN("")
EndProcedure
 
If OpenConsole()=0 : End 1 : EndIf
put(0,25)
put(250,265)
put(1000,1025)
Input()</lang>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th </pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">_suffix = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']
 
def nth(n):
Line 2,991 ⟶ 3,875:
if __name__ == '__main__':
for j in range(0,1001, 250):
print(' '.join(nth(i) for i in list(range(j, j+25))))</langsyntaxhighlight>
{{out}}
<pre>0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th
Line 2,999 ⟶ 3,883:
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th</pre>
'''Alternate version'''
<langsyntaxhighlight lang="python">#!/usr/bin/env python3
 
def ord(n):
Line 3,013 ⟶ 3,897:
print(*(ord(n) for n in range(26)))
print(*(ord(n) for n in range(250,266)))
print(*(ord(n) for n in range(1000,1026)))</langsyntaxhighlight>
{{out}}
<pre>
Line 3,027 ⟶ 3,911:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ table ] is suffix ( n --> $ )
 
$ "th st nd rd th th th th th th"
Line 3,050 ⟶ 3,934:
250 265 test
cr
1000 1025 test</langsyntaxhighlight>
 
{{out}}
Line 3,069 ⟶ 3,953:
{{trans|Python}}
Note that R vectors are 1-indexed.
<langsyntaxhighlight lang="rsplus">nth <- function(n)
{
if (length(n) > 1) return(sapply(n, nth))
Line 3,086 ⟶ 3,970:
range <- list(0:25, 250:275, 500:525, 750:775, 1000:1025)
 
sapply(range, nth)</langsyntaxhighlight>
{{out}}
<pre> [,1] [,2] [,3] [,4] [,5]
Line 3,119 ⟶ 4,003:
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">#lang racket
(define (teen? n) (<= 11 (modulo n 100) 19))
(define (Nth n)
Line 3,128 ⟶ 4,012:
 
(for ((range (list (in-range 26) (in-range 250 266) (in-range 1000 1026))))
(displayln (string-join (for/list ((nth (sequence-map Nth range))) nth) " ")))</langsyntaxhighlight>
{{out}}
<pre>0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 25'th
Line 3,137 ⟶ 4,021:
(formerly Perl 6)
(Spurious apostrophes intentionally omitted.)
<syntaxhighlight lang="raku" perl6line>my %irregulars = <1 st 2 nd 3 rd>, (11..13 X=> 'th');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'th' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</langsyntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
Line 3,147 ⟶ 4,031:
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
If you want to get Unicodally fancy, use this version instead:
<syntaxhighlight lang="raku" perl6line>my %irregulars = <1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ>, (11..13 X=> 'ᵗʰ');
 
sub nth ($n) { $n ~ ( %irregulars{$n % 100} // %irregulars{$n % 10} // 'ᵗʰ' ) }
 
say .list».&nth for [^26], [250..265], [1000..1025];</langsyntaxhighlight>
{{out}}
<blockquote>0ᵗʰ 1ˢᵗ 2ⁿᵈ 3ʳᵈ 4ᵗʰ 5ᵗʰ 6ᵗʰ 7ᵗʰ 8ᵗʰ 9ᵗʰ 10ᵗʰ 11ᵗʰ 12ᵗʰ 13ᵗʰ 14ᵗʰ 15ᵗʰ 16ᵗʰ 17ᵗʰ 18ᵗʰ 19ᵗʰ 20ᵗʰ 21ˢᵗ 22ⁿᵈ 23ʳᵈ 24ᵗʰ 25ᵗʰ<br>
Line 3,158 ⟶ 4,042:
 
=={{header|Red}}==
<langsyntaxhighlight lang="rebol">Red[]
 
nth: function [n][
d: n % 10
dd: n % 100
suffix: either any [d < 1 d > 4 1 = to-integer n / 10] [4] [d]
suffix: either any [ all [ dd > 3 dd < 20 ] d < 1 d > 4 1 = to-integer n / 10] [4] [d]
rejoin [n pick ["st" "nd" "rd" "th"] suffix]
]
Line 3,175 ⟶ 4,060:
test 0 25
test 250 265
test 1000 1025</langsyntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011st1011th 1012nd1012th 1013rd1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Show 0 25>
<Show 250 265>
<Show 1000 1025>;
};
 
Nth {
s.N, <Symb s.N>: {
e.X '1' s.Y = e.X '1' s.Y 'th';
e.X '1' = e.X '1st';
e.X '2' = e.X '2nd';
e.X '3' = e.X '3rd';
e.X = e.X 'th';
};
};
 
Cell {
s.N, <First 8 <Nth s.N> ' '>: (e.1) e.2 = e.1;
}
 
Group {
s.N e.1 = <Group (s.N s.N) () e.1>;
(s.N s.M) (e.1) = (e.1);
(s.N 0) (e.1) e.2 = (e.1) <Group (s.N s.N) () e.2>;
(s.N s.M) (e.1) s.2 e.3 = <Group (s.N <- s.M 1>) (e.1 s.2) e.3>;
};
 
Iota {
s.End s.End = s.End;
s.Start s.End = s.Start <Iota <+ s.Start 1> s.End>;
};
 
Each {
s.F = ;
s.F t.I e.X = <Mu s.F t.I> <Each s.F e.X>;
};
 
ShowLine {
(e.Line) = <Prout <Each Cell e.Line>>;
};
 
Show {
s.Start s.End,
<Iota s.Start s.End>: e.Range,
<Group 10 e.Range>: e.Lines
= <Prout <Each ShowLine e.Lines>>;
};</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
10th 11th 12th 13th 14th 15th 16th 17th 18th 19th
20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th
260th 261st 262nd 263rd 264th 265th
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|REXX}}==
This version adds suffixes without apostrophes.
 
Negative numbers and fractions are also handled.
 
<lang rexx>/*REXX program shows ranges of numbers with ordinal (st/nd/rd/th) suffixes attached.*/
Two alternate solutions added to the oiginal
call tell 0, 25 /*display the 1st range of numbers. */
<syntaxhighlight lang="rexx">/*REXX program shows ranges of numbers with ordinal (st/nd/rd/th) suffixes attached.*/
call tell 250, 265 /* " " 2nd " " " */
callCall tell 10000, 1025 25 /* display " " 3rd " " the "1st range of numbers */
exitCall tell 250,265 /* " " 2nd " " /*stick a fork in it," we're all done. */
Call tell 1000,1025 /* " " 3rd " " " */
/*──────────────────────────────────────────────────────────────────────────────────────*/
tell:Exit procedure; parse arg L,H,,$ /*get thestick Lowa andfork Highin #sit, nullify listwe're all done */
/*-------------------------------------------------------------------------*/
do j=L to H; $=$ th(j); end /*process the range, from low ───► high*/
tell: Procedure
say 'numbers from ' L " to " H ' (inclusive):' /*display the title. */
Parse Arg low,high say strip($); say; say /* get the Low and High numbers /*display line; 2 sep*/
out.=''
return /*return to invoker. */
Do n=low To high /* process the range, from low */
/*──────────────────────────────────────────────────────────────────────────────────────*/
out.1=out.1 th(n)
th: parse arg z; x=abs(z); return z||word('th st nd rd',1+x//10*(x//100%10\==1)*(x//10<4))</lang>
out.2=out.2 th2(n)
out.3=out.3 th3(n)
End
Say 'numbers from' low 'to' high '(inclusive):' /*display the output */
Say strip(out.1)
Say ''
If out.2<>out.1 Then Say 'th2 must be wrong'
If out.3<>out.1 Then Say 'th3 must be wrong'
Return
/*-------------------------------------------------------------------------*/
th: /* compact original */
Parse Arg z
x=abs(z)
Return z||word('th st nd rd',1+x//10*(x//100%10\==1)*(x//10<4))
/*-------------------------------------------------------------------------*/
th2: /* rather verbose logic */
Parse Arg z
x=abs(z)
Select
When length(x)=1 Then
If x<4 Then
suffix=word('th st nd rd',x+1)
Else
suffix='th'
When suffixstr(x,length(x)-1,1)=1 Then
suffix='th'
When right(x,1)<4 Then
suffix=word('th st nd rd',right(x,1)+1)
Otherwise
suffix='th'
End
Return z||suffix
/*-------------------------------------------------------------------------*/
th3: /* compact yet quite readable */
Parse Arg z
Parse Value reverse(z) with last +1 prev +1
If last<4 &, /* last digit is 0,1,2,3 */
prev<>1 Then /* and number is not **1x */
suffix=word('th st nd rd',last+1)
Else /* all oher cases */
suffix='th'
Return z||suffix</syntaxhighlight>
'''output''' &nbsp; using the default inputs:
<pre>
Line 3,215 ⟶ 4,202:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
for nr = 0 to 25
see Nth(nr) + Nth(nr + 250) + Nth(nr + 1000) + nl
Line 3,231 ⟶ 4,218:
func Nth n
return "" + n + "'" + getSuffix(n) + " "
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
===Clean version===
≪ IP DUP 10 MOD OVER 100 MOD 10 / IP → units tens
≪ →STR "'" +
'''IF''' units 1 ≥ units 3 ≤ AND tens 1 ≠ AND
'''THEN''' { "st" "nd" "rd" } units GET
'''ELSE''' "th"
'''END'''
+
≫ ≫ '<span style="color:blue">NTH</span>' STO
===One-liner===
This version uses a mix of arithmetic and boolean operations to determine when to apply the "st/nd/rd" exception.
≪ IP →STR LAST { "'th" "'st" "'nd" "'rd" } OVER 10 MOD DUP 4 < * ROT 100 MOD 10 / IP 1 ≠ * 1 + GET + ≫ '<span style="color:blue">NTH</span>' STO
 
≪ { } ROT ROT '''FOR''' j j <span style="color:blue">NTH</span> + '''NEXT''' ≫
'<span style="color:blue">SHOW</span>' STO
0 25 <span style="color:blue">SHOW</span>
250 265 <span style="color:blue">SHOW</span>
1000 1025 <span style="color:blue">SHOW</span>
{{out}}
<pre>
3: { "0'th" "1'st" "2'nd" "3'rd" "4'th" "5'th" "6'th" "7'th" "8'th" "9'th" "10'th" "11'th" "12'th" "13'th" "14'th" "15'th" "16'th" "17'th" "18'th" "19'th" "20'th" "21'st" "22'nd" "23'rd" "24'th" "25'th" }
2: { "250'th" "251'st" "252'nd" "253'rd" "254'th" "255'th" "256'th" "257'th" "258'th" "259'th" "260'th" "261'st" "262'nd" "263'rd" "264'th" "265'th" }
1: { "1000'th" "1001'st" "1002'nd" "1003'rd" "1004'th" "1005'th" "1006'th" "1007'th" "1008'th" "1009'th" "1010'th" "1011'th" "1012'th" "1013'th" "1014'th" "1015'th" "1016'th" "1017'th" "1018'th" "1019'th" "1020'th" "1021'st" "1022'nd" "1023'rd" "1024'th" "1025'th" }
</pre>
 
=={{header|Ruby}}==
Code (slightly adapted) and methodname taken from ActiveSupport (Ruby on Rails).
<langsyntaxhighlight lang="ruby">class Integer
def ordinalize
num = self.abs
Line 3,253 ⟶ 4,268:
 
[(0..25),(250..265),(1000..1025)].each{|r| puts r.map(&:ordinalize).join(", "); puts}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,264 ⟶ 4,279:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn nth(num: isize) -> String {
format!("{}{}", num, match (num % 10, num % 100) {
(1, 11) | (2, 12) | (3, 13) => "th",
Line 3,283 ⟶ 4,298:
println!();
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,295 ⟶ 4,310:
 
=={{header|Scala}}==
{{libheader|Scala}}<langsyntaxhighlight Scalalang="scala">object Nth extends App {
def abbrevNumber(i: Int) = print(s"$i${ordinalAbbrev(i)} ")
 
Line 3,314 ⟶ 4,329:
println();
(1000 to 1025).foreach(abbrevNumber)
}</langsyntaxhighlight>
 
=={{header|sed}}==
<syntaxhighlight lang="sed">/1.$/!{s/1$/1st/;s/2$/2nd/;s/3$/3rd/;};s/[0-9]$/&th/</syntaxhighlight>
{{out}}
<pre>
$ for n in 0 250 1000; do echo $(seq $n $((n + 25)) | sed -f nth.sed); done
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th 266th 267th 268th 269th 270th 271st 272nd 273rd 274th 275th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func string: suffix (in integer: num) is func
Line 3,345 ⟶ 4,370:
printImages( 250, 265);
printImages(1000, 1025);
end func;</langsyntaxhighlight>
 
{{out}}
Line 3,354 ⟶ 4,379:
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program nth;
loop for r in [[0..25], [250..265], [1000..1025]] do
showrange(r);
end loop;
 
proc showrange(r);
i := 0;
loop for s in [nth(n) : n in r] do
putchar(rpad(s, 8));
if (i +:= 1) mod 6 = 0 then print(); end if;
end loop;
print();
end proc;
 
proc nth(n);
sfx := {[1,"st"], [2,"nd"], [3,"rd"]};
return str n +
if n div 10 mod 10 = 1
then "th"
else sfx(n mod 10) ? "th"
end if;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th
6th 7th 8th 9th 10th 11th
12th 13th 14th 15th 16th 17th
18th 19th 20th 21st 22nd 23rd
24th 25th
250th 251st 252nd 253rd 254th 255th
256th 257th 258th 259th 260th 261st
262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th
1006th 1007th 1008th 1009th 1010th 1011th
1012th 1013th 1014th 1015th 1016th 1017th
1018th 1019th 1020th 1021st 1022nd 1023rd
1024th 1025th</pre>
=={{header|Set lang}}==
Due to the language's specification, the input can only contain one character. Therefore, the following code only works with 0-9.
<langsyntaxhighlight lang="set_lang">set o 49
set t 50
set h 51
Line 3,376 ⟶ 4,439:
set ! R
set ! D
> EOF</langsyntaxhighlight>
Input: I, Output: O
<pre>I: 1, O: 1'ST
Line 3,387 ⟶ 4,450:
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">func nth(n) {
static irregulars = Hash(<1 ˢᵗ 2 ⁿᵈ 3 ʳᵈ 11 ᵗʰ 12 ᵗʰ 13 ᵗʰ>...)
n.to_s + (irregulars{n % 100} \\ irregulars{n % 10} \\ 'ᵗʰ')
Line 3,394 ⟶ 4,457:
for r in [0..25, 250..265, 1000..1025] {
say r.map {|n| nth(n) }.join(" ")
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,401 ⟶ 4,464:
1000ᵗʰ 1001ˢᵗ 1002ⁿᵈ 1003ʳᵈ 1004ᵗʰ 1005ᵗʰ 1006ᵗʰ 1007ᵗʰ 1008ᵗʰ 1009ᵗʰ 1010ᵗʰ 1011ᵗʰ 1012ᵗʰ 1013ᵗʰ 1014ᵗʰ 1015ᵗʰ 1016ᵗʰ 1017ᵗʰ 1018ᵗʰ 1019ᵗʰ 1020ᵗʰ 1021ˢᵗ 1022ⁿᵈ 1023ʳᵈ 1024ᵗʰ 1025ᵗʰ
</pre>
 
=={{header|Sinclair ZX81 BASIC}}==
Works flawlessly with 2k or more of RAM. With 1k, the subroutine itself works but you can't quite print all the tests: the program crashes with an 'out of memory' error code after 1017th. (A slightly less useful and readable version gets as far as 1023rd; 1025th is probably attainable, but might involve obfuscating the program more than is appropriate for this site.)
<lang basic> 10 FOR N=0 TO 25
20 GOSUB 160
30 PRINT N$;" ";
40 NEXT N
50 PRINT
60 FOR N=250 TO 265
70 GOSUB 160
80 PRINT N$;" ";
90 NEXT N
100 PRINT
110 FOR N=1000 TO 1025
120 GOSUB 160
130 PRINT N$;" ";
140 NEXT N
150 STOP
160 LET N$=STR$ N
170 LET S$="TH"
180 IF LEN N$=1 THEN GOTO 200
190 IF N$(LEN N$-1)="1" THEN GOTO 230
200 IF N$(LEN N$)="1" THEN LET S$="ST"
210 IF N$(LEN N$)="2" THEN LET S$="ND"
220 IF N$(LEN N$)="3" THEN LET S$="RD"
230 LET N$=N$+S$
240 RETURN</lang>
{{out}}
<pre>
0TH 1ST 2ND 3RD 4TH 5TH 6TH 7TH 8TH 9TH 10TH 11TH 12TH 13TH 14TH 15TH 16TH 17TH 18TH 19TH 20TH 21ST 22ND 23RD 24TH 25TH
250TH 251ST 252ND 253RD 254TH 255TH 256TH 257TH 258TH 259TH 260TH 261ST 262ND 263RD 264TH 265TH
1000TH 1001ST 1002ND 1003RD 1004TH 1005TH 1006TH 1007TH 1008TH 1009TH 1010TH 1011TH 1012TH 1013TH 1014TH 1015TH 1016TH 1017TH 1018TH 1019TH 1020TH 1021ST 1022ND 1023RD 1024TH 1025TH</pre>
 
=={{header|SQL}}==
Oracle
<syntaxhighlight lang="sql">
<lang SQL>
select level card,
to_char(to_date(level,'j'),'fmjth') ord
Line 3,444 ⟶ 4,475:
select to_char(to_date(5373485,'j'),'fmjth')
from dual;
</syntaxhighlight>
</lang>
<pre>
CARD ORD
Line 3,473 ⟶ 4,504:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">local
val v = Vector.tabulate (10, fn 1 => "st" | 2 => "nd" | 3 => "rd" | _ => "th")
fun getSuffix x =
Line 3,484 ⟶ 4,515:
(* some test ouput *)
val () = (print o concat o List.tabulate)
(26, fn i => String.concatWith "\t" (map nth [i, i + 250, i + 1000]) ^ "\n")</langsyntaxhighlight>
{{out}}
<pre>0th 250th 1000th
Line 3,516 ⟶ 4,547:
We reuse here the '''maps''' function defined in the task [[Apply a callback to an array]].
 
<langsyntaxhighlight lang="stata">mata
function maps(f,a) {
nr = rows(a)
Line 3,533 ⟶ 4,564:
 
maps(&nth(),((0::25),(250::275),(1000::1025)))
end</langsyntaxhighlight>
 
'''Output:'''
Line 3,566 ⟶ 4,597:
26 | 25th 275th 1025th |
+----------------------------+</pre>
 
=={{header|Stringle}}==
<syntaxhighlight lang="stringle">#i
s "th"
.\#i "1" .:\#i !"1" s "st"
.\#i "2" .:\#i !"1" s "nd"
.\#i "3" .:\#i !"1" s "rd"
$ #i s
i i "."
#i +26 26 +#i #@i 250
#i +266 266 +#i #@i 1000
#i +1026 i ""
#i</syntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight Swiftlang="swift">func addSuffix(n:Int) -> String {
if n % 100 / 10 == 1 {
return "th"
Line 3,596 ⟶ 4,640:
print("\(i)\(addSuffix(i)) ")
}
println()</langsyntaxhighlight>
{{out}}
<pre>
Line 3,605 ⟶ 4,649:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc ordinal {n} {
if {$n%100<10 || $n%100>20} {
set suff [lindex {th st nd rd th th th th th th} [expr {$n % 10}]]
Line 3,619 ⟶ 4,663:
}
puts $l
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,627 ⟶ 4,671:
</pre>
 
== {{header|TypeScript}} ==
{{trans|Ada}}
<syntaxhighlight lang="javascript">
// N'th
function suffix(n: number): string {
var nMod10: number = n % 10;
var nMod100: number = n % 100;
if (nMod10 == 1 && nMod100 != 11)
return "st";
else if (nMod10 == 2 && nMod100 != 12)
return "nd";
else if (nMod10 == 3 && nMod100 != 13)
return "rd";
else
return "th";
}
 
function printImages(loLim: number, hiLim: number) {
=={{header|True BASIC}}==
for (i = loLim; i <= hiLim; i++)
<lang basic>
process.stdout.write(`${i}` + suffix(i) + " ");
SUB sufijo (n)
process.stdout.write("\n");
LET n = INT(n)
}
LET NMod10 = MOD(n, 10)
LET NMod100 = MOD(n, 100)
printImages( 0, 25);
IF (NMod10 = 1) AND (NMod100 <> 11) THEN
printImages( 250, 265);
LET sufi$ = "st"
printImages(1000, 1025);
ELSE
</syntaxhighlight>
IF (NMod10 = 2) AND (NMod100 <> 12) THEN
LET sufi$ = "nd"
ELSE
IF (NMod10 = 3) AND (NMod100 <> 13) THEN
LET sufi$ = "rd"
ELSE
LET sufi$ = "th"
END IF
END IF
END IF
PRINT sufi$;
END SUB
 
SUB imprimeOrdinal (loLim, hiLim)
LET loLim = INT(loLim)
LET hiLim = INT(hiLim)
FOR i = loLim TO hiLim
PRINT i;
CALL sufijo (i)
PRINT " ";
NEXT i
PRINT
END SUB
 
CALL imprimeOrdinal (0, 25)
CALL imprimeOrdinal (250, 265)
CALL imprimeOrdinal (1000, 1025)
END
</lang>
 
 
=={{header|uBasic/4tH}}==
<lang>For x = 0 to 25 ' Test range 0..25
Push x : GoSub _PrintOrdinal
Next x : Print
 
For x = 250 to 265 ' Test range 250..265
Push x : GoSub _PrintOrdinal
Next x : Print
 
For x = 1000 to 1025 ' Test range 1000..1025
Push x : GoSub _PrintOrdinal
Next x : Print
 
End ' End test program
' ( n --)
_PrintOrdinal ' Ordinal subroutine
If Tos() > -1 Then ' If within range then
Print Using "____#";Tos();"'"; ' Print the number
' Take care of 11, 12 and 13
If (Tos()%100 > 10) * (Tos()%100 < 14) Then
Gosub (Pop() * 0) + 100 ' Clear stack and print "th"
Return ' We're done here
EndIf
 
Push Pop() % 10 ' Calculate n mod 10
GoSub 100 + 10 * ((Tos()>0) + (Tos()>1) + (Tos()>2) - (3 * (Pop()>3)))
Else ' And decide which ordinal to use
Print Pop();" is less than zero" ' Otherwise, it is an error
EndIf
 
Return
' Select and print proper ordinal
100 Print "th"; : Return
110 Print "st"; : Return
120 Print "nd"; : Return
130 Print "rd"; : Return</lang>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
0'th 1'st 2'nd 3'rd 4'th 5'th 6'th 7'th 8'th 9'th 10'th 11'th 12'th 13'th 14'th 15'th 16'th 17'th 18'th 19'th 20'th 21'st 22'nd 23'rd 24'th 25'th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
250'th 251'st 252'nd 253'rd 254'th 255'th 256'th 257'th 258'th 259'th 260'th 261'st 262'nd 263'rd 264'th 265'th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th 1025'th
</pre>
 
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
<langsyntaxhighlight lang="sh">nth() {
local ordinals=(th st nd rd)
local -i n=$1 i
Line 3,728 ⟶ 4,722:
for n in {0..25} {250..265} {1000..1025}; do
nth $n
done | column</langsyntaxhighlight>
 
{{Out}}
Line 3,739 ⟶ 4,733:
6th 13th 20th 251st 258th 265th 1006th 1013th 1020th</pre>
 
=={{header|VBAV (Vlang)}}==
{{trans|go}}
{{trans|Phix}}<lang vb>Private Function ordinals() As Variant
<syntaxhighlight lang="v (vlang)">fn ord(n int) string {
ordinals = [{"th","st","nd","rd"}]
mut s := "th"
End Function
c := n % 10
if c in [1,2,3] {
if n%100/10 == 1 {
return "$n$s"
}
match c {
1 {
s = 'st'
}
2 {
s = 'nd'
}
3 {
s = 'rd'
}
else{}
}
}
return "$n$s"
}
fn main() {
for n := 0; n <= 25; n++ {
print("${ord(n)} ")
}
println('')
for n := 250; n <= 265; n++ {
print("${ord(n)} ")
}
println('')
for n := 1000; n <= 1025; n++ {
print("${ord(n)} ")
}
println('')
}</syntaxhighlight>
 
{{out}}
Private Function Nth(n As Variant, Optional apostrophe As Boolean = False) As String
<pre>
Dim mod10 As Integer: mod10 = n Mod 10 + 1
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
If mod10 > 4 Or n Mod 100 = mod10 + 9 Then mod10 = 1
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
Nth = CStr(n) & String$(Val(-apostrophe), "'") & ordinals()(mod10)
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
End Function
</pre>
 
=={{header|VTL-2}}==
Public Sub main()
The subroutine at 2000 sets S and T to the first and second letters of the suffix for N. The subroutine at 3000 prints N and the suffix.
Ranges = [{0,25;250,265;1000,1025}]
<syntaxhighlight lang="vtl2">
For i = 1 To UBound(Ranges)
1110 N=0
For j = Ranges(i, 1) To Ranges(i, 2)
1120 #=3000
If j Mod 10 = 0 Then Debug.Print
1130 N=N+1
Debug.Print Format(Nth(j, i = 2), "@@@@@@@");
1140 #=N<26*1120
Next j
1150 ?=" "
Debug.Print
1210 N=250
Next i
1220 #=3000
End Sub</lang>{{out}}
1230 N=N+1
<pre> 0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th
1240 #=N<266*1220
10th 11th 12th 13th 14th 15th 16th 17th 18th 19th
1250 ?=" "
20th 21st 22nd 23rd 24th 25th
1310 N=1000
1320 #=3000
1330 N=N+1
1340 #=N<1026*1320
1350 ?=" "
1400 #=9999
2000 R=!
2010 S=116
2020 T=104
2030 M=N/100*0+%
2040 #=M<20+(M>4)=2*R
2050 M=N/10*0+%
2060 #=M=1=0*2100
2070 S=115
2080 T=116
2090 #=R
2100 #=M=2=0*2140
2110 S=110
2120 T=100
2130 #=R
2140 #=M=3=0*R
2150 S=114
2160 T=100
2170 #=R
3000 Z=!
3010 $=32
3020 ?=N
3030 #=2000
3040 $=S
3050 $=T
3060 #=Z
</syntaxhighlight>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
 
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
250'th 251'st 252'nd 253'rd 254'th 255'th 256'th 257'th 258'th 259'th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
260'th 261'st 262'nd 263'rd 264'th 265'th
</pre>
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th
1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for ConvFmt
 
var ranges = [ 0..25, 250..265, 1000..1025 ]
for (r in ranges) {
r.each { |i| SystemFmt.write("%(Conv.ord(i))$r ", i) }
System.print("\n")
}</langsyntaxhighlight>
 
{{out}}
Line 3,788 ⟶ 4,850:
 
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|XBasic}}==
{{trans|Ada}}
{{works with|Windows XBasic}}
<lang xbasic>
PROGRAM "nth"
VERSION "0.0002"
 
DECLARE FUNCTION Entry()
INTERNAL FUNCTION Suffix$(n&&)
INTERNAL FUNCTION PrintImages (loLim&&, hiLim&&)
 
FUNCTION Entry()
PrintImages( 0, 25)
PrintImages( 250, 265)
PrintImages(1000, 1025)
END FUNCTION
 
FUNCTION Suffix$(n&&)
nMod10@@ = n&& MOD 10
nMod100@@ = n&& MOD 100
SELECT CASE TRUE
CASE (nMod10@@ = 1) AND (nMod100@@ <> 11):
RETURN ("st")
CASE (nMod10@@ = 2) AND (nMod100@@ <> 12):
RETURN ("nd")
CASE (nMod10@@ = 3) AND (nMod100@@ <> 13):
RETURN ("rd")
CASE ELSE:
RETURN ("th")
END SELECT
END FUNCTION
 
FUNCTION PrintImages(loLim&&, hiLim&&)
FOR i&& = loLim&& TO hiLim&&
PRINT TRIM$(STRING$(i&&)); Suffix$(i&&); " ";
NEXT
PRINT
END FUNCTION
END PROGRAM
</lang>
{{out}}
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|XLISP}}==
<langsyntaxhighlight lang="xlisp">(DEFUN NTH (N)
(COND
((AND (> (MOD N 100) 3) (< (MOD N 100) 21)) `(,N TH))
Line 3,857 ⟶ 4,872:
(DISPLAY (MAPCAR NTH (RANGE 1000 1025))))
 
(TEST-NTH)</langsyntaxhighlight>
{{out}}
<pre>((1 ST) (2 ND) (3 RD) (4 TH) (5 TH) (6 TH) (7 TH) (8 TH) (9 TH) (10 TH) (11 TH) (12 TH) (13 TH) (14 TH) (15 TH) (16 TH) (17 TH) (18 TH) (19 TH) (20 TH) (21 ST) (22 ND) (23 RD) (24 TH) (25 TH))
Line 3,863 ⟶ 4,878:
((1000 TH) (1001 ST) (1002 ND) (1003 RD) (1004 TH) (1005 TH) (1006 TH) (1007 TH) (1008 TH) (1009 TH) (1010 TH) (1011 TH) (1012 TH) (1013 TH) (1014 TH) (1015 TH) (1016 TH) (1017 TH) (1018 TH) (1019 TH) (1020 TH) (1021 ST) (1022 ND) (1023 RD) (1024 TH) (1025 TH))</pre>
 
=={{header|XPL0}}==
{{trans|Ada}}
{{works with|EXPL-32}}
<syntaxhighlight lang="xpl0">
\N'th
code Rem=2, CrLf=9, IntIn=10, IntOut=11, Text=12;
 
procedure Suf(N, S);
=={{header|Yabasic}}==
integer N;
{{trans|Liberty BASIC}}
character S;
<lang xbasic>
integer NMod10, NMod100;
sub ordinal$ (n)
begin
NMod10 = mod(n, 10)
NMod100 NMod10:= modRem(n,N/10); 100)
NMod100:= Rem(N/100);
if (NMod10 = 1) and (NMod100 <> 11) then
case of
return "st"
NMod10 = 1 & NMod100 # 11: S(0):= "st";
else
if (NMod10 = 2) and& (NMod100 <># 12: S(0):= then"nd";
NMod10 = 3 & NMod100 # return13: S(0):= "ndrd"
other
else
S(0):= "th";
if (NMod10 = 3) and (NMod100 <> 13) then
end;
return "rd"
else
return "th"
end if
end if
end if
end sub
 
procedure PrintImages(LoLim, HiLim);
sub imprimeOrdinal(a, b)
integer LoLim, HiLim;
for i = a to b
integer I;
print i, ordinal$(i), " ";
character S; next i
printbegin
for I:= LoLim, HiLim do
end sub
begin
Suf(I, addr S);
IntOut(0, I); Text(0, S); Text(0, " ")
end;
CrLf(0)
end;
 
begin
imprimeOrdinal (0, 25)
PrintImages(0, 25);
imprimeOrdinal (250, 265)
PrintImages(250, 265);
imprimeOrdinal (1000, 1025)
PrintImages(1000, 1025)
end
</syntaxhighlight>
</lang>
{{out}}
 
<pre>
0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th
1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th
</pre>
 
=={{header|zkl}}==
Two versions, your choice
<langsyntaxhighlight lang="zkl">#if 0
fcn addSuffix(n){
z:=n.abs()%100;
Line 3,914 ⟶ 4,941:
String(n,(z<=10 or z>20) and suffixes[z%10] or "th");
}
#endif</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">[0..25] .apply(addSuffix).concat(",").println();
[250..265] .apply(addSuffix).concat(",").println();
[1000..1025].apply(addSuffix).concat(",").println();</langsyntaxhighlight>
{{out}}
<pre>
Line 3,924 ⟶ 4,951:
1000th,1001st,1002nd,1003rd,1004th,1005th,1006th,1007th,1008th,1009th,1010th,1011th,1012th,1013th,1014th,1015th,1016th,1017th,1018th,1019th,1020th,1021st,1022nd,1023rd,1024th,1025th
</pre>
 
=={{header|ZX Spectrum Basic}}==
<lang basic> 10 FOR n=0 TO 25
20 GO SUB 140
30 PRINT n$;" ";
40 NEXT n
50 FOR n=250 TO 265
60 GO SUB 140
70 PRINT n$;" ";
80 NEXT n
90 FOR n=1000 TO 1025
100 GO SUB 140
110 PRINT n$;" ";
120 NEXT n
130 STOP
140 LET s$="th"
150 LET n$=STR$ n
160 IF LEN n$=1 THEN GO TO 180
170 IF n$(LEN n$-1)="1" THEN GO TO 210
180 IF n$(LEN n$)="1" THEN LET s$="st"
190 IF n$(LEN n$)="2" THEN LET s$="nd"
200 IF n$(LEN n$)="3" THEN LET s$="rd"
210 LET n$=n$+s$
220 RETURN</lang>
{{out}}
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11th 12th 13th 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th 250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th 1000th 1001st 1002nd 1003rd 1004th 1005th 1006th 1007th 1008th 1009th 1010th 1011th 1012th 1013th 1014th 1015th 1016th 1017th 1018th 1019th 1020th 1021st 1022nd 1023rd 1024th 1025th</pre>
2,093

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.