N'th: Difference between revisions
Content added Content deleted
m (→{{header|Red}}: Added missing output) |
(Dialects of BASIC moved to the BASIC section.) |
||
Line 613: | Line 613: | ||
"1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th", |
"1014th", "1015th", "1016th", "1017th", "1018th", "1019th", "1020th", |
||
"1021st", "1022nd", "1023rd", "1024th", "1025th"}}</pre> |
"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}}== |
=={{header|Arturo}}== |
||
Line 768: | Line 745: | ||
1008'th 1007'th 1006'th 1005'th 1004'th 1003'rd 1002'nd 1001'st 1000'th</pre> |
1008'th 1007'th 1006'th 1005'th 1004'th 1003'rd 1002'nd 1001'st 1000'th</pre> |
||
=={{header| |
=={{header|BASIC}}== |
||
==={{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) |
<syntaxhighlight lang="freebasic">' Nth (sans apostrophes) |
||
FUNCTION nth$(NUMBER n) TYPE STRING |
FUNCTION nth$(NUMBER n) TYPE STRING |
||
Line 810: | Line 811: | ||
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11</pre> |
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11</pre> |
||
=={{header|BASIC}}== |
|||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
<syntaxhighlight lang="basic256"> |
<syntaxhighlight lang="basic256"> |
||
Line 842: | Line 842: | ||
end |
end |
||
</syntaxhighlight> |
</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}}=== |
==={{header|Commodore BASIC}}=== |
||
Line 895: | Line 954: | ||
022'nd 1023'rd 1024'th 1025'th |
022'nd 1023'rd 1024'th 1025'th |
||
</pre> |
</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}}=== |
==={{header|Nascom BASIC}}=== |
||
Line 934: | Line 1,191: | ||
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 |
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> |
</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}}=== |
==={{header|QBasic}}=== |
||
Line 974: | Line 1,256: | ||
END FUNCTION |
END FUNCTION |
||
</syntaxhighlight> |
</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}}== |
=={{header|Batch File}}== |
||
Line 1,006: | Line 1,544: | ||
"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" |
"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" |
||
Press any key to continue . . . |
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> |
</pre> |
||
Line 1,396: | Line 1,909: | ||
Set [1000,1025] : |
Set [1000,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> |
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|Clojure}}== |
=={{header|Clojure}}== |
||
Line 2,055: | Line 2,534: | ||
end program nth</syntaxhighlight> |
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}}== |
=={{header|Go}}== |
||
Line 2,176: | Line 2,579: | ||
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th |
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 |
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> |
</pre> |
||
Line 2,562: | Line 2,925: | ||
1021st 1022nd 1023rd 1024th 1025th |
1021st 1022nd 1023rd 1024th 1025th |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{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|Lua}}== |
=={{header|Lua}}== |
||
Line 2,733: | Line 3,051: | ||
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 |
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> |
</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}}== |
=={{header|MiniScript}}== |
||
Line 3,489: | Line 3,770: | ||
true. |
true. |
||
</pre> |
</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}}== |
=={{header|Python}}== |
||
Line 3,865: | Line 4,121: | ||
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 |
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> |
</pre> |
||
=={{header|Run BASIC}}== |
|||
The [[#Liberty_BASIC|Liberty BASIC]] solution works without any changes. |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Line 4,017: | Line 4,270: | ||
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ᵗʰ |
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> |
</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}}== |
=={{header|SQL}}== |
||
Line 4,242: | Line 4,463: | ||
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 |
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> |
</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}} == |
== {{header|TypeScript}} == |
||
Line 4,315: | Line 4,496: | ||
250th 251st 252nd 253rd 254th 255th 256th 257th 258th 259th 260th 261st 262nd 263rd 264th 265th |
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 |
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> |
</pre> |
||
Line 4,387: | Line 4,525: | ||
5th 12th 19th 250th 257th 264th 1005th 1012th 1019th |
5th 12th 19th 250th 257th 264th 1005th 1012th 1019th |
||
6th 13th 20th 251st 258th 265th 1006th 1013th 1020th</pre> |
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)}}== |
=={{header|V (Vlang)}}== |
||
Line 4,537: | Line 4,643: | ||
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 |
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> |
</pre> |
||
Line 4,659: | Line 4,718: | ||
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 |
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> |
</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}}== |
=={{header|zkl}}== |
||
Line 4,720: | Line 4,744: | ||
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 |
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> |
</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> |