C program to Accept a character and display its previous and next character - IProgramX

Q. Accept a character from the keyboard and display its previous and next character in order.Ex. If the character entered is ‘d’, display “The previous character is c”, “The next character is e”.


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

3 Comments

  1. show algorithm & flowchart of this C program

    ReplyDelete
  2. Write a c program to read character from keyboard and display the entered character

    ReplyDelete
  3. Accept 5character display them

    ReplyDelete