c++高手请进来

来源:百度知道 编辑:UC知道 时间:2024/06/16 22:17:54
输入一个小写字母,如果是大写字母转换成小写字母
如果是大写字母,转换成小写字母
这个怎麽搞阿?

是大写变小写 小写变大写吧
#include<iostream.h>
main()
{
char c;
cin>>c;
if(c>='A'&&c<='Z')
c=c+32;
else if(c>='a'&&c<='z')
c=c-32;
else c='0';
if(c=='0')
cout<<"error";
else cout<<c<<endl;
}

看下边的吧~

#include<iostream.h>
using namespace std
main(){
char str;
cin>>str;
if(str>='a'&&str<='z')
str=str-32;
else if(str>='A'&&str<='Z')
str=str+32;
else
cout<<"error"<<endl;
cout<<str<<endl;
}