Jump to content

N'th: Difference between revisions

212 bytes added ,  11 months ago
→‎{{header|PowerShell}}: Fixed 11th, 112th and 13th
(→‎{{header|Batch File}}: Fixed 11tth, 12th and 13th)
(→‎{{header|PowerShell}}: Fixed 11th, 112th and 13th)
Line 3,207:
 
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">function nth($inp){
function nth($inp){
$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 11st11th 12nd12th 13rd13th 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,233 ⟶ 3,244:
$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,249 ⟶ 3,266:
{{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>
 
3,038

edits

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