-5

I wanted to convert an integer to a letter. For example:

1 = A
2 = B
3 = C
...
26 = Z

Is there a way I could do this without using an array?

Etheryte
  • 22,936
  • 11
  • 65
  • 109

1 Answers1

3

You could use code like

int i = 1; // or 2, 3, ... 26
char resultChar = i + 'A' - 1; // resultChar will be 'A' or 'B' etc.
Reinhard Männer
  • 12,311
  • 4
  • 51
  • 100