index | submit | rank | book

ordinal – Ordinal numerals

A podium: 1st, 2nd and 3rd

In English, we can abbreviate an ordinal numeral by appending the last two letters of the word with the corresponding number. For example, “first” can be abbreviated as “1st”; “second” can be formatted as “2nd”; “third” can be formatted as “3rd”; “fourth” can be formatted as “4th”.

Write a program that given some numbers, formats the corresponding English ordinal numerals.

Each line of input contains a natural number n where 0 < n < 10 000.

For each line of input there should be a line of output with the number given on the input followed by the English ordinal suffix.

Example input

1
2
3
4
56

Example output

1st
2nd
3rd
4th
56th

The suffix and ordinal functions

Your program should be implemented using two functions suffix and ordinal. The suffix function should return a string with just the suffix. The ordinal function should return a string with the abbreviated ordinal — the number followed by the suffix. Please refer to the information for your chosen language:

Scoring

try first: oddeven calc

index | submit | rank | book

Copyright © 2020-2023 Rudy Matela
All rights reserved