编程:实现从键盘输入一个字符时,如果该字符为小写字母,则转换为大写字母输出;如果该字符为大写字母,则转换为小写字母输出;如果为其他字符,则原样输出。
#include<stdio.h>
int main()
{
char x,y;
printf("请输入一个字符:");
scanf("%c",&x);
if(x>='A'&&x<='Z')
{
y=x+32;
printf("此字母是一个大写字母,转换后的小写字母是:%c",y);
}
else if(x>='a'&&x<='z')
{
y=x-32;
printf("此字母是一个小写字母,转换后的大写字母是%c",y);
}
else
{
printf("%c",x);
}
return 0;
}
记得点个采纳,谢谢
#include "stdio.h"
int main(){
char c;
scanf("%c",&c);
if(c>='A' && c<='Z')
c= c+32;
else if(c>='a' && c<='z'){
c = c-32;
}
printf("转换后的字母c=%c",c);
return 0;
}
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
scanf("%c",&c);
if(c>='A' && c<='Z')
{
printf("%c\n",tolower(c));
}
else if(c>='a' && c<='z')
{
printf("%c\n",toupper(c));
}
else
{
printf("%c\n",c);
}
return 0;
}
C语言有专门的大小写转化函数tolower和toupper,熟练运用挺好
代码如下:
#include "stdio.h"
void main()
{
char ch;
scanf("%c",&ch);
if(ch >= 'a' && ch <= 'z')
ch = ch - 32;
else if(ch >= 'A' && ch <= 'Z')
ch = ch + 32;
printf("%c\n",ch);
}
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632