N'th: Difference between revisions

15,941 bytes added ,  1 month ago
m
fix typo
m (Corrected Forth code to produce 1011th, 1012th,1013th instead of 1011st, 1012nd, 1013rd)
m (fix typo)
 
(30 intermediate revisions by 13 users not shown)
Line 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 551 ⟶ 613:
"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|Arturo}}==
Line 706 ⟶ 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}}===
{{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
Line 748 ⟶ 850:
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11</pre>
 
=={{header|BASIC}}==
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256">
Line 780 ⟶ 881:
end
</syntaxhighlight>
 
==={{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}}===
Line 833 ⟶ 993:
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}}===
Line 872 ⟶ 1,230:
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}}===
Line 912 ⟶ 1,295:
END FUNCTION
</syntaxhighlight>
 
==={{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}}==
Line 926 ⟶ 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</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"
Press any key to continue . . .</pre>
 
=={{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>
 
Line 1,626 ⟶ 2,245:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func$ nth num . ordinal$ .
num$last2 = num mod 100
lastTwoDigits$last = substr num$ len num$ - 1mod 210
lastDigit$if last2 >= substr11 num$and lenlast2 num$<= 113
return num & "th"
if lastTwoDigits$ = "11" or lastTwoDigits$ = "12" or lastTwoDigits$ = "13"
elif ordinal$last = num$ & "th"1
elif lastDigit$ = return num & "1st"
elif ordinal$last = num$ & "st"2
elif lastDigit$ = return num & "2nd"
elif ordinal$last = num$ & "nd"3
elif lastDigit$ = return num & "3rd"
ordinal$ = num$ & "rd"
else
ordinal$ =return num$ & "th"
.
.
print "0 to 25:"
for i = 0 to 25
callwrite nth i ordinal$& " "
write ordinal$
write " "
.
print ""
print "250 to 265:"
for i = 250 to 265
callwrite nth i ordinal$& " "
write ordinal$
write " "
.
print ""
print "1000 to 1025:"
for i = 1000 to 1025
callwrite nth i ordinal$& " "
write ordinal$
write " "
.
</syntaxhighlight>
Line 1,675 ⟶ 2,287:
=={{header|Elena}}==
{{trans|C#}}
ELENA 56.0x :
<syntaxhighlight lang="elena">import extensions;
import system'math;
Line 1,685 ⟶ 2,297:
{
int i := self.Absolute;
if (new int[]{11,12,13}.ifExists(i.mod:(100)))
{
^ i.toPrintable() + "th"
Line 1,821 ⟶ 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}}==
Line 1,954 ⟶ 2,589:
 
end program nth</syntaxhighlight>
 
=={{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|Go}}==
Line 2,075 ⟶ 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}}
<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>
 
Line 2,166 ⟶ 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 2,345 ⟶ 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}}==
Line 2,461 ⟶ 3,021:
1021st 1022nd 1023rd 1024th 1025th
</syntaxhighlight>
 
=={{header|Liberty BASIC}}==
{{trans|Ada}}
{{works with|Just BASIC|any}}
<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|Lua}}==
Line 2,631 ⟶ 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}}
<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|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">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,680 ⟶ 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,690 ⟶ 3,171:
test 250, 265
test 1000, 1025
print out.join</syntaxhighlight>
 
{{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}}==
Line 3,165 ⟶ 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 "$_")};""</syntaxhighlight>
</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===
Line 3,193 ⟶ 3,792:
$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 3,209 ⟶ 3,814:
{{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 3,261 ⟶ 3,866:
true.
</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|Python}}==
Line 3,466 ⟶ 4,046:
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,484 ⟶ 4,065:
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.
 
<syntaxhighlight 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))</syntaxhighlight>
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,539 ⟶ 4,222:
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
===ReadableClean 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===
'NTH' STO
===Compact version===
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
OVER 10 MOD DUP 4 < * ROT 100 MOD 10 / IP 1 ≠ * 1 + GET +
'NTH' STO
 
≪ { } 3ROT ROLLDROT '''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>
Line 3,652 ⟶ 4,330:
(1000 to 1025).foreach(abbrevNumber)
}</syntaxhighlight>
 
=={{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}}==
Line 3,691 ⟶ 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.
Line 3,738 ⟶ 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.)
<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|SQL}}==
Line 3,903 ⟶ 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}}==
Line 3,963 ⟶ 4,670:
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|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|TypeScript}} ==
Line 4,036 ⟶ 4,703:
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|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>
 
Line 4,108 ⟶ 4,732:
5th 12th 19th 250th 257th 264th 1005th 1012th 1019th
6th 13th 20th 251st 258th 265th 1006th 1013th 1020th</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|V (Vlang)}}==
Line 4,186 ⟶ 4,778:
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|VTL-2}}==
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.
<syntaxhighlight lang="vtl2">
1110 N=0
1120 #=3000
1130 N=N+1
1140 #=N<26*1120
1150 ?=" "
1210 N=250
1220 #=3000
1230 N=N+1
1240 #=N<266*1220
1250 ?=" "
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
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}}
<syntaxhighlight lang="ecmascriptwren">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")
}</syntaxhighlight>
Line 4,205 ⟶ 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}}
<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>
 
Line 4,327 ⟶ 4,925:
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|zkl}}==
Line 4,388 ⟶ 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}}==
<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>
2,093

edits