题目描述:
编写一个程序,可以一直接收键盘字符,如果是小写字符就输出对应的大写字符,如果接收的是大写字符,就输出对应的小写字符,如果是数字不输出。
主要思想:
先判断输入的是否大小写字母,再用字符的ASCII码值进行计算即可完成大小写字母的转换。
即:A+32=a
完整代码
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdlib.h>
#include <stdio.h>
int main()
{
int ch=0;
printf("请输入内容;");
while ((ch = getchar()) != 0)
{
if (ch<='z'&&ch>='a')
{
printf("%c", ch - 32);
}
if (ch<='Z'&&ch>='A')
{
printf("%c", ch + 32);
}
if (ch<='9'&&ch>='0')
printf(" ");
}
printf("\n");
system("pause");
return 0;
}