code4sk/c/sourcecode/朱森森带领的奇妙冒险/字符串1/字符串字母大小写转换.cpp
2023-10-18 16:17:32 +08:00

34 lines
748 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//字符串字母大小写转换
//本题要求编写程序,对一个以“#”结束的字符串,将其小写字母全部转换成大写字母,把大写字母全部转换成小写字母,其他字符不变输出。
//输入格式:
//输入为一个以“#”结束的字符串不超过30个字符
//输出格式:
//在一行中输出大小写转换后的结果字符串。
///输入样例:
//Hello World! 123#
//输出样例:
//hELLO wORLD! 123
#include<stdio.h>
int main()
{
char c;
while((c=getchar())!='#')//当输入的不是‘# 则进入循环
{
if(c>='A'&&c<='Z')//如果输入是大写
{
c+=32;
printf("%c",c);
}
else if(c>='a'&&c<='z')//如果输入是小写
{
c-=32;
printf("%c",c);
}
else//输入是其他
printf("%c",c);
}
return 0;
}