与字母相关的库函数
isupper:判断大写字母 islower:判断小写字母 toupper转换为大写字母 tolower:转换位小写字母 以上四个函数头文件均为:<ctype.h>
题目
 原题链接: https://www.nowcoder.com/practice/91a588dd4cd244bfa616f17603ec123c?tpId=107&&tqId=33328&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking
解题代码
#include<stdio.h>
#include<ctype.h>
int main()
{
int ch = 0;
while (~scanf("%c", &ch))
{
if (isupper(ch))
printf("%c\n", tolower(ch));
else if (islower(ch))
printf("%c\n", toupper(ch));
getchar();
}
return 0;
}
代码中getchar()函数的作用
在while循环时会读取上一次循环剩下的\n,getchar函数的作用就是消除\n;
运行结果
 
结语:为了我们三月的风,六月的雨,九月的风景而不懈努力。
|