Jump to content

N'th: Difference between revisions

297 bytes added ,  3 years ago
→‎{{header|UNIX Shell}}: Add implementation
m (→‎{{header|Phix}}: added a functional version using builtins and corrected a syntax colouring error)
(→‎{{header|UNIX Shell}}: Add implementation)
Line 3,276:
1000'th 1001'st 1002'nd 1003'rd 1004'th 1005'th 1006'th 1007'th 1008'th 1009'th 1010'th 1011'th 1012'th 1013'th 1014'th 1015'th 1016'th 1017'th 1018'th 1019'th 1020'th 1021'st 1022'nd 1023'rd 1024'th 1025'th
</pre>
 
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
<lang sh>nth() {
local ordinals=(th st nd rd)
local -i n=$1 i
case $(( n % 100 )) in
11|12|13) i=0;;
*) (( i = n%10 ))
if (( i > 3 )); then i=0; fi
;;
esac
printf '%d%s\n' "$n" "${ordinals[i]}"
}</lang>
 
=={{header|VBA}}==
1,481

edits

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