Generate suffix

How can I generate suffix for integers from 1 to 10 to the power of 10000?

EXAMPLE 1:
input: 21
output: 21st

EXAMPLE 2:
input: 111
output: 111th

EXAMPLE 3:
input: 23656111
output: 23656111th
Last edited on
I do not know about any standard library function that does that for you but you can implement something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int ones_place =  n % 10;
int tens_place = ( n / 10 ) % 10;
if (tens_place != 1) {
  switch (ones_place) {
    case 0:
      addSuffix( n, "th" ); // assuming you have a function addSuffix
      break;
    case 1:
      addSuffix( n, "st" );
      break;
    ...
  }
} else { // if tens_place == 1
  addSuffix( n, "th" );
}
Thank you for your help. It makes me clearer about suffix now! :)
Topic archived. No new replies allowed.