重邮F021考纲算法(c++)04大小写字母转换
·
#include <iostream>
#include <cctype>
using namespace std;
void toUpper(char &c) {
if (c >= 'a' && c <= 'z') {
c -= 32;
}
}
void toLower(char &c) {
if (c >= 'A' && c <= 'Z') {
c += 32;
}
}
int main() {
char c;
cout << "请输入一个字符:" << endl;
cin >> c;
// toUpper(c);
c = toupper(c); // 自带函数
cout << "转大写字母:" << c <<endl;
// toLower(c);
c = tolower(c); // 自带函数
cout << "转小写字母:" << c << endl;
return 0;
}
更多推荐

所有评论(0)