Search code examples
c

Shift a letter down the alphabet?


I.E., you enter the number 5, and the character A and the output would yield F. I have no idea how to even start to go about this, any give me a push in the right direction?


Solution

  • Individual characters are represented by numbers according to the ASCII code (usually). In C, if you add a number to a character, you're shifting the character down. Try:

    char c = 'A';
    int n = 5;
    printf("%c\n", c + n);