#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;
}

更多推荐