输入格式要求: 提示信息:"Press a key and then press Enter:" 输出格式要求: "%c, %d\n" 程序运行示例1如下: Press a key and then press Enter:A a, 97 程序运行示例2如下: Press a key and then press Enter:a A, 65
#include<stdio.h>
int main()
{
char x;
printf("%s","Press a key and then press Enter:");
x=getchar();
if(65<= x && x<=90)printf("%c, %d\n",x-'A'+'a',x-'A'+'a');//注意不要写成65<=x<=90
else if(97<= x && x<=122)printf("%c, %d\n",x+'A'-'a',x+'A'-'a');
else printf("%c",x);
return 0;
}
大写字母转换为小写字母:
x-'A'+'a' || x+32
小写字母转换为大写字母:
x+'A'-'a' || x-32