输入格式要求: 提示信息:"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
该程序示例展示了如何接收用户输入的一个字符,并根据ASCII码进行大小写的转换。如果输入的是大写字母,它会转换为小写;如果是小写字母,则转换为大写。对于非字母字符,程序则原样输出。
4425

被折叠的 条评论
为什么被折叠?



