-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
  • 24,589
  • 11
  • 71
  • 116

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
  • 14,022
  • 5
  • 54
  • 116