C Program - Accept a character from the keyboard and display it's previous and next character in order

Program

#include <stdio.h>
int main()
{
char ch;
printf("Enter character:\t");
scanf("%c", &ch);
printf("You entered: %c\n", ch);
printf("Previous character: %c\n", ch - 1);
printf("Next character: %c\n", ch + 1);
}

Output:

Enter character:        f
You entered: f
Previous character: e
Next character: g

Post a Comment

0 Comments