Skip to content

English Ordinal Suffix for an Integer

Return st, nd, rd, or th for an integer, treating 11, 12, and 13 as th.

Language: C

Added on: 21st August 2026

const char *ord(int value)
{
    if (value > 10 && value < 20) {
        return "th";
    }
    switch (value % 10) {
    case 1:
        return "st";
    case 2:
        return "nd";
    case 3:
        return "rd";
    default:
        return "th";
    }
}

Caveats

Only the values 11-19 use the teen rule. 111 returns st because the check is not applied to 111.