WeixiangYan/CodeTransOcean huggingface dataset:
Task: N'th



C#: using System;
using System.Linq;

class Program
{
    private static string Ordinalize(int i)
    {
        i = Math.Abs(i);

        if (new[] {11, 12, 13}.Contains(i%100))
            return i + "th";

        switch (i%10)
        {
            case 1:
                return i + "st";
            case 2:
                return i + "nd";
            case 3:
                return i + "rd";
            default:
                return i + "th";
        }
    }

    static void Main()
    {
        Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
    }
}
Task: N'th


C++: #include <string>
#include <iostream>

using namespace std;

string Suffix(int num)
{
    switch (num % 10)
    {
        case 1 : if(num % 100 != 11) return "st";
           break;
        case 2 : if(num % 100 != 12) return "nd";
           break;
        case 3 : if(num % 100 != 13) return "rd";
    }

    return "th";
}

int main()
{
    cout << "Set [0,25]:" << endl;
    for (int i = 0; i < 26; i++)
        cout << i << Suffix(i) << " ";
    
    cout << endl;

    cout << "Set [250,265]:" << endl;
    for (int i = 250; i < 266; i++)
        cout << i << Suffix(i) << " ";
   
    cout << endl;

    cout << "Set [1000,1025]:" << endl;
    for (int i = 1000; i < 1026; i++)
        cout << i << Suffix(i) << " ";
   
    cout << endl;

    return 0;
}
Task: N'th





Java: public class Nth {
	public static String ordinalAbbrev(int n){
		String ans = "th"; 
		if(n % 100 / 10 == 1) return ans; 
		switch(n % 10){
			case 1: ans = "st"; break;
			case 2: ans = "nd"; break;
			case 3: ans = "rd"; break;
		}
		return ans;
	}
	
	public static void main(String[] args){
		for(int i = 0; i <= 25;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
		System.out.println();
		for(int i = 250; i <= 265;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
		System.out.println();
		for(int i = 1000; i <= 1025;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
	}
}
Task: N'th







Python: _suffix = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']

def nth(n):
    return "%i'%s" % (n, _suffix[n%10] if n % 100 <= 10 or n % 100 > 20 else 'th')

if __name__ == '__main__':
    for j in range(0,1001, 250):
        print(' '.join(nth(i) for i in list(range(j, j+25))))
Task: N'th








VB: Private Function ordinals() As Variant
    ordinals = [{"th","st","nd","rd"}]
End Function

Private Function Nth(n As Variant, Optional apostrophe As Boolean = False) As String
    Dim mod10 As Integer: mod10 = n Mod 10 + 1
    If mod10 > 4 Or n Mod 100 = mod10 + 9 Then mod10 = 1
    Nth = CStr(n) & String$(Val(-apostrophe), "
End Function

Public Sub main()
    Ranges = [{0,25;250,265;1000,1025}]
    For i = 1 To UBound(Ranges)
        For j = Ranges(i, 1) To Ranges(i, 2)
            If j Mod 10 = 0 Then Debug.Print
            Debug.Print Format(Nth(j, i = 2), "@@@@@@@");
        Next j
        Debug.Print
    Next i
End Sub
Task: N'th




Go: package main

import "fmt"

func ord(n int) string {
    s := "th"
    switch c := n % 10; c {
    case 1, 2, 3:
        if n%100/10 == 1 {
            break
        }
        switch c {
        case 1:
            s = "st"
        case 2:
            s = "nd"
        case 3:
            s = "rd"
        }
    }
    return fmt.Sprintf("%d%s", n, s)
}

func main() {
    for n := 0; n <= 25; n++ {
        fmt.Printf("%s ", ord(n))
    }
    fmt.Println()
    for n := 250; n <= 265; n++ {
        fmt.Printf("%s ", ord(n))
    }
    fmt.Println()
    for n := 1000; n <= 1025; n++ {
        fmt.Printf("%s ", ord(n))
    }
    fmt.Println()
}
Task: N'th



C#: using System;
using System.Linq;

class Program
{
    private static string Ordinalize(int i)
    {
        i = Math.Abs(i);

        if (new[] {11, 12, 13}.Contains(i%100))
            return i + "th";

        switch (i%10)
        {
            case 1:
                return i + "st";
            case 2:
                return i + "nd";
            case 3:
                return i + "rd";
            default:
                return i + "th";
        }
    }

    static void Main()
    {
        Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
    }
}








Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th


C++: #include <string>
#include <iostream>

using namespace std;

string Suffix(int num)
{
    switch (num % 10)
    {
        case 1 : if(num % 100 != 11) return "st";
           break;
        case 2 : if(num % 100 != 12) return "nd";
           break;
        case 3 : if(num % 100 != 13) return "rd";
    }

    return "th";
}

int main()
{
    cout << "Set [0,25]:" << endl;
    for (int i = 0; i < 26; i++)
        cout << i << Suffix(i) << " ";
    
    cout << endl;

    cout << "Set [250,265]:" << endl;
    for (int i = 250; i < 266; i++)
        cout << i << Suffix(i) << " ";
   
    cout << endl;

    cout << "Set [1000,1025]:" << endl;
    for (int i = 1000; i < 1026; i++)
        cout << i << Suffix(i) << " ";
   
    cout << endl;

    return 0;
}









Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th

C: #include <stdio.h>
 
char* addSuffix(int num, char* buf, size_t len)
{
    char *suffixes[4] = { "th", "st", "nd", "rd" };
    int i;

    switch (num % 10)
    {
        case 1 : i = (num % 100 == 11) ? 0 : 1;
	         break;
        case 2 : i = (num % 100 == 12) ? 0 : 2;
                 break;
        case 3 : i = (num % 100 == 13) ? 0 : 3;
                 break;
        default: i = 0;
    };
 
    snprintf(buf, len, "%d%s", num, suffixes[i]);
    return buf;
}

int main(void)
{
    int i;

    printf("Set [0,25]:\n");
    for (i = 0; i < 26; i++)
    {
        char s[5];
        printf("%s ", addSuffix(i, s, 5));
    }
    putchar('\n'); 

    printf("Set [250,265]:\n");
    for (i = 250; i < 266; i++)
    {
        char s[6];
        printf("%s ", addSuffix(i, s, 6));
    }
    putchar('\n'); 

    printf("Set [1000,1025]:\n");
    for (i = 1000; i < 1026; i++)
    {
        char s[7];
        printf("%s ", addSuffix(i, s, 7));
    }
    putchar('\n');

    return 0;
}










Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th





Java: public class Nth {
	public static String ordinalAbbrev(int n){
		String ans = "th"; 
		if(n % 100 / 10 == 1) return ans; 
		switch(n % 10){
			case 1: ans = "st"; break;
			case 2: ans = "nd"; break;
			case 3: ans = "rd"; break;
		}
		return ans;
	}
	
	public static void main(String[] args){
		for(int i = 0; i <= 25;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
		System.out.println();
		for(int i = 250; i <= 265;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
		System.out.println();
		for(int i = 1000; i <= 1025;i++){
			System.out.print(i + ordinalAbbrev(i) + " ");
		}
	}
}






Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th







Python: _suffix = ['th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th']

def nth(n):
    return "%i'%s" % (n, _suffix[n%10] if n % 100 <= 10 or n % 100 > 20 else 'th')

if __name__ == '__main__':
    for j in range(0,1001, 250):
        print(' '.join(nth(i) for i in list(range(j, j+25))))




Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th








VB: Private Function ordinals() As Variant
    ordinals = [{"th","st","nd","rd"}]
End Function

Private Function Nth(n As Variant, Optional apostrophe As Boolean = False) As String
    Dim mod10 As Integer: mod10 = n Mod 10 + 1
    If mod10 > 4 Or n Mod 100 = mod10 + 9 Then mod10 = 1
    Nth = CStr(n) & String$(Val(-apostrophe), "
End Function

Public Sub main()
    Ranges = [{0,25;250,265;1000,1025}]
    For i = 1 To UBound(Ranges)
        For j = Ranges(i, 1) To Ranges(i, 2)
            If j Mod 10 = 0 Then Debug.Print
            Debug.Print Format(Nth(j, i = 2), "@@@@@@@");
        Next j
        Debug.Print
    Next i
End Sub



Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th






PHP: function nth($num) {
  $os = "th";
  if ($num % 100 <= 10 or $num % 100 > 20) {
    switch ($num % 10) {
      case 1:
        $os = "st";
        break;
      case 2:
        $os = "nd";
        break;
      case 3:
        $os = "rd";
        break;
    }
  } 
  return $num . $os;
}

foreach ([[0,25], [250,265], [1000,1025]] as $i) {
  while ($i[0] <= $i[1]) {
    echo nth($i[0]) . " ";
    $i[0]++;
  }
  echo "\n";
}





Fortran: 































program nth
  implicit none
  logical :: need
  integer :: here, there, n, i, iostat
  read(5,*,iostat=iostat) here, there
  if (iostat .ne. 0) then
     write(6,*)'such bad input never before seen.'
     write(6,*)'I AYE EYE QUIT
     call exit(1)
  end if
  need = .false.
  n = abs(there - here) + 1
  i = 0
  do while (0 /= mod(3+mod(here-i, 3), 3))
     write(6,'(a22)',advance='no') ''
     i = i+1
  end do
  do i = here, there, sign(1, there-here)
     write(6,'(a22)',advance='no') ordinate(i)
     if (2 /= mod(i,3)) then
        need = .true.
     else
        write(6,'(a)')''
        need = .false.
     end if
  end do
  if (need) write(6,'(a)')''

contains

  character(len=22) function ordinate(n)
    character(len=19) :: a
    character(len=20), parameter :: &
         &a09 =   "thstndrdthththththth",&
         &ateen = "thththththththththth"
    integer :: ones, tens, ones_index
    integer, intent(in) :: n
    write(a,'(i19)') n
    ones = mod(n,10)
    tens = mod(n,100)
    ones_index = ones*2+1
    if (n < 1000) then
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // "'" // ateen(ones_index:ones_index+1)
          
       else
          ordinate = a // "'" // a09(ones_index:ones_index+1)
          
       end if
    else
       if ((10 .le. tens) .and. (tens .lt. 20)) then
          ordinate = a // ateen(ones_index:ones_index+1)
       else
          ordinate = a // a09(ones_index:ones_index+1)
       end if
    end if
  end function ordinate

end program nth
Task: N'th

C: #include <stdio.h>
 
char* addSuffix(int num, char* buf, size_t len)
{
    char *suffixes[4] = { "th", "st", "nd", "rd" };
    int i;

    switch (num % 10)
    {
        case 1 : i = (num % 100 == 11) ? 0 : 1;
	         break;
        case 2 : i = (num % 100 == 12) ? 0 : 2;
                 break;
        case 3 : i = (num % 100 == 13) ? 0 : 3;
                 break;
        default: i = 0;
    };
 
    snprintf(buf, len, "%d%s", num, suffixes[i]);
    return buf;
}

int main(void)
{
    int i;

    printf("Set [0,25]:\n");
    for (i = 0; i < 26; i++)
    {
        char s[5];
        printf("%s ", addSuffix(i, s, 5));
    }
    putchar('\n'); 

    printf("Set [250,265]:\n");
    for (i = 250; i < 266; i++)
    {
        char s[6];
        printf("%s ", addSuffix(i, s, 6));
    }
    putchar('\n'); 

    printf("Set [1000,1025]:\n");
    for (i = 1000; i < 1026; i++)
    {
        char s[7];
        printf("%s ", addSuffix(i, s, 7));
    }
    putchar('\n');

    return 0;
}









COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. NTH-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  WS-NUMBER.
    05 N               PIC 9(8).
    05 LAST-TWO-DIGITS PIC 99.
    05 LAST-DIGIT      PIC 9.
    05 N-TO-OUTPUT     PIC Z(7)9.
    05 SUFFIX          PIC AA.
PROCEDURE DIVISION.
TEST-PARAGRAPH.
    PERFORM NTH-PARAGRAPH VARYING N FROM 0 BY 1 UNTIL N IS GREATER THAN 25.
    PERFORM NTH-PARAGRAPH VARYING N FROM 250 BY 1 UNTIL N IS GREATER THAN 265.
    PERFORM NTH-PARAGRAPH VARYING N FROM 1000 BY 1 UNTIL N IS GREATER THAN 1025.
    STOP RUN.
NTH-PARAGRAPH.
    MOVE 'TH' TO SUFFIX.
    MOVE N (7:2) TO LAST-TWO-DIGITS.
    IF LAST-TWO-DIGITS IS LESS THAN 4,
    OR LAST-TWO-DIGITS IS GREATER THAN 20,
    THEN PERFORM DECISION-PARAGRAPH.
    MOVE N TO N-TO-OUTPUT.
    DISPLAY N-TO-OUTPUT WITH NO ADVANCING.
    DISPLAY SUFFIX WITH NO ADVANCING.
    DISPLAY SPACE WITH NO ADVANCING.
DECISION-PARAGRAPH.
    MOVE N (8:1) TO LAST-DIGIT.
    IF LAST-DIGIT IS EQUAL TO 1 THEN MOVE 'ST' TO SUFFIX.
    IF LAST-DIGIT IS EQUAL TO 2 THEN MOVE 'ND' TO SUFFIX.
    IF LAST-DIGIT IS EQUAL TO 3 THEN MOVE 'RD' TO SUFFIX.
Task: N'th



C#: using System;
using System.Linq;

class Program
{
    private static string Ordinalize(int i)
    {
        i = Math.Abs(i);

        if (new[] {11, 12, 13}.Contains(i%100))
            return i + "th";

        switch (i%10)
        {
            case 1:
                return i + "st";
            case 2:
                return i + "nd";
            case 3:
                return i + "rd";
            default:
                return i + "th";
        }
    }

    static void Main()
    {
        Console.WriteLine(string.Join(" ", Enumerable.Range(0, 26).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(250, 16).Select(Ordinalize)));
        Console.WriteLine(string.Join(" ", Enumerable.Range(1000, 26).Select(Ordinalize)));
    }
}







COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. NTH-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  WS-NUMBER.
    05 N               PIC 9(8).
    05 LAST-TWO-DIGITS PIC 99.
    05 LAST-DIGIT      PIC 9.
    05 N-TO-OUTPUT     PIC Z(7)9.
    05 SUFFIX          PIC AA.
PROCEDURE DIVISION.
TEST-PARAGRAPH.
    PERFORM NTH-PARAGRAPH VARYING N FROM 0 BY 1 UNTIL N IS GREATER THAN 25.
    PERFORM NTH-PARAGRAPH VARYING N FROM 250 BY 1 UNTIL N IS GREATER THAN 265.
    PERFORM NTH-PARAGRAPH VARYING N FROM 1000 BY 1 UNTIL N IS GREATER THAN 1025.
    STOP RUN.
NTH-PARAGRAPH.
    MOVE 'TH' TO SUFFIX.
    MOVE N (7:2) TO LAST-TWO-DIGITS.
    IF LAST-TWO-DIGITS IS LESS THAN 4,
    OR LAST-TWO-DIGITS IS GREATER THAN 20,
    THEN PERFORM DECISION-PARAGRAPH.
    MOVE N TO N-TO-OUTPUT.
    DISPLAY N-TO-OUTPUT WITH NO ADVANCING.
    DISPLAY SUFFIX WITH NO ADVANCING.
    DISPLAY SPACE WITH NO ADVANCING.
DECISION-PARAGRAPH.
    MOVE N (8:1) TO LAST-DIGIT.
    IF LAST-DIGIT IS EQUAL TO 1 THEN MOVE 'ST' TO SUFFIX.
    IF LAST-DIGIT IS EQUAL TO 2 THEN MOVE 'ND' TO SUFFIX.
    IF LAST-DIGIT IS EQUAL TO 3 THEN MOVE 'RD' TO SUFFIX.