N'th: Difference between revisions

Content added Content deleted
(→‎{{header|Batch File}}: Fixed 11tth, 12th and 13th)
(→‎{{header|PowerShell}}: Fixed 11th, 112th and 13th)
Line 3,207: Line 3,207:


=={{header|PowerShell}}==
=={{header|PowerShell}}==
<syntaxhighlight lang="powershell">function nth($inp){
<syntaxhighlight lang="powershell">
function nth($inp){
$suffix = "th"
$suffix = "th"


switch($inp % 10){
switch($inp % 100){
1{$suffix="st"}
11{$suffix="th"}
2{$suffix="nd"}
12{$suffix="th"}
3{$suffix="rd"}
13{$suffix="th"}
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 "$_")};""
0..25 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
250..265 | %{Write-host -nonewline (nth "$_")};""
1000..1025 | %{Write-host -nonewline (nth "$_")};""</syntaxhighlight>
1000..1025 | %{Write-host -nonewline (nth "$_")};""
</syntaxhighlight>
{{Out}}
{{Out}}
<pre>
<pre>0th 1st 2nd 3rd 4th 5th 6th 7th 8th 9th 10th 11st 12nd 13rd 14th 15th 16th 17th 18th 19th 20th 21st 22nd 23rd 24th 25th
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
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 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>


===An Alternate Version===
===An Alternate Version===
Line 3,233: Line 3,244:
$suffix = "th"
$suffix = "th"


switch ($Number % 10)
switch ($Number % 100){
11 {$suffix = "th"}
{
1 {$suffix = "st"}
12 {$suffix = "th"}
2 {$suffix = "nd"}
13 {$suffix = "th"}
3 {$suffix = "rd"}
default {
switch ($Number % 10){
1 {$suffix = "st"}
2 {$suffix = "nd"}
3 {$suffix = "rd"}
}
}
}
}


Line 3,249: Line 3,266:
{{Out}}
{{Out}}
<pre>
<pre>
1st 2nd 3rd 4th 5th
1st 2nd 3rd 4th 5th
6th 7th 8th 9th 10th
6th 7th 8th 9th 10th
11st 12nd 13rd 14th 15th
11th 12th 13th 14th 15th
16th 17th 18th 19th 20th
16th 17th 18th 19th 20th
21st 22nd 23rd 24th 25th
21st 22nd 23rd 24th 25th




251st 252nd 253rd 254th 255th
251st 252nd 253rd 254th 255th
256th 257th 258th 259th 260th
256th 257th 258th 259th 260th
261st 262nd 263rd 264th 265th
261st 262nd 263rd 264th 265th




1001st 1002nd 1003rd 1004th 1005th
1001st 1002nd 1003rd 1004th 1005th
1006th 1007th 1008th 1009th 1010th
1006th 1007th 1008th 1009th 1010th
1011st 1012nd 1013rd 1014th 1015th
1011th 1012th 1013th 1014th 1015th
1016th 1017th 1018th 1019th 1020th
1016th 1017th 1018th 1019th 1020th
1021st 1022nd 1023rd 1024th 1025th
1021st 1022nd 1023rd 1024th 1025th
</pre>
</pre>