c语言编程题:从键盘输入一个字符,输出与该字符前后相邻的两个字符及对应的ASCII码,要求输出时按ASCII码

2024-11-06 23:02:09
推荐回答(2个)
回答1:

char ch;
scanf(" %c",&ch);
printf("%c %c\n",(char)(ch-1),(char)(ch+1));
printf("%d %d\n",(ch-1),(ch+1));

回答2:

#include

int main(void)
{
char a;
a=getchar();
printf("%c:%d\n%c:%d\n%c:%d\n",a-1,a-1,a,a,a+1,a+1);
return 0;
}