N'th: Difference between revisions

1,253 bytes added ,  10 months ago
→‎{{header|ANSI BASIC}}: Added a solution.
(Dialects of BASIC moved to the BASIC section.)
(→‎{{header|ANSI BASIC}}: Added a solution.)
Line 746:
 
=={{header|BASIC}}==
==={{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
511

edits