N'th: Difference between revisions

+ forth
m ({{out}} / Category:String manipulation)
(+ forth)
Line 440:
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|Forth}}==
<lang forth>: 'nth ( -- c-addr ) s" th st nd rd th th th th th th " drop ;
: .nth ( n -- )
dup 10 20 within if 0 .r ." th " exit then
dup 0 .r 10 mod 3 * 'nth + 3 type ;
 
: test ( n n -- ) cr do i 5 mod 0= if cr then i .nth loop ;
: tests ( -- )
26 0 test 266 250 test 1026 1000 test ;
 
tests</lang>
 
{{out}}
<pre>0th 1st 2nd 3rd 4th
5th 6th 7th 8th 9th
10th 11th 12th 13th 14th
15th 16th 17th 18th 19th
20th 21st 22nd 23rd 24th
25th
 
250th 251st 252nd 253rd 254th
255th 256th 257th 258th 259th
260th 261st 262nd 263rd 264th
265th
 
1000th 1001st 1002nd 1003rd 1004th
1005th 1006th 1007th 1008th 1009th
1010th 1011st 1012nd 1013rd 1014th
1015th 1016th 1017th 1018th 1019th
1020th 1021st 1022nd 1023rd 1024th
1024th ok</pre>
 
=={{header|Fortran}}==
Anonymous user