编写一个程序,可以一直接收键盘字符。如果是小写字符就输出对应的大写字符,如果接收的是大写字符就输出对应的小写字符,如果是数字不输出。
解析:
可以利用ASCII码对字符进行转换。先将输入的字符转换为ASCII码,再对ASCII码进行加减运算,最后将运算后的ASCI码转化为字符输出。
代码:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
int main(){
char i;
int j;
printf("请输入一个字符:\n");
//一直接收,创建一个循环
while (1){
//接收字符
scanf("%c", &i);
j = i;
//小写=>大写
if (j > 64 && j < 91){
j += 32;
printf("转换后:%c\n", j);
}//大写=>小写
else if (j>96 && j < 123){
j -= 32;
printf("转换后:%c\n", j);
}
}
system("pause");
return 0;
}
运行结果: