输入一个字符串,将其中的大写字母改为小写字母,小写字母改为大写字母,然后输出!...

C语言作业: 输入一个字符串,将其中的大写字母改为小写字母,小写字母改为大写字母,然后输出!...   给我个详细的答案!..谢谢额!

#include<stdio.h>

int main()

{char s[200];

int i;

gets(s);

for(i=0;s[i];i++)

if(s[i]>='A'&&s[i]<='Z')s[i]+=32;

else if(s[i]>='a'&&s[i]<='z')s[i]-=32;

puts(s);  

return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-01
#include <stdio.h>void main()
{
char z[100];
scanf("%s",z);

char *p=z;
while(*p)
{
if(*p>='a'&&*p<='z')
{
*p-=32;
}
else if(*p>='A'&&*p<='Z')
{
*p+=32;
}
p++;
}
printf("%s\n",z);
}
第2个回答  推荐于2018-02-27
以下程序通过测试. 有问题请追问!#include <stdio.h>void main()
{
char s[30];
scanf("%s",s);

char *p=s;
while(*p)
{
if(*p>='a'&&*p<='z')
{
*p-=32;
}
else if(*p>='A'&&*p<='Z')
{
*p+=32;
}
p++;
}
printf("%s\n",s);
}附图:本回答被网友采纳
第3个回答  2017-06-13
百度 C语言 大小写

~
~
~
相似回答