用c++编写小写字母转换为大写字母
时间: 2024-01-21 14:17:49 浏览: 31
以下是一个简单的 C++ 代码示例,用于将输入的小写字母转换为大写字母:
```cpp
#include <iostream>
#include <cctype>
using namespace std;
int main() {
char c;
cout << "Enter a lowercase letter: ";
cin >> c;
if (islower(c)) {
c = toupper(c);
cout << "The uppercase letter is: " << c << endl;
} else {
cout << "You did not enter a lowercase letter." << endl;
}
return 0;
}
```
该程序首先提示用户输入一个小写字母,然后使用 `islower()` 函数检查用户输入的字符是否为小写字母。如果是,使用 `toupper()` 函数将其转换为大写字母,并输出结果。否则,程序将提示用户重新输入。
相关问题
用c++ 6.0编写一个程序,将小写字母转换为大写字母。
以下是将用户输入的小写字母转换为大写字母并输出的C++程序:
```c++
#include <iostream>
#include <ctype.h>
using namespace std;
int main() {
char ch;
cout << "请输入一个小写字母:";
cin >> ch;
ch = toupper(ch);
cout << "转换后的大写字母是:" << ch << endl;
return 0;
}
```
程序通过 `toupper()` 函数将用户输入的小写字母转换为大写字母,然后输出转换后的结果。
用c++ 编写程序完成大写字母的小写转换
```
#include<stdio.h>
int main()
{
char c;
printf("请输入一个大写字母:\n");
scanf("%c",&c);
c = c + 32; //将大写字母转换成小写字母
printf("转换后的小写字母为:%c\n",c);
return 0;
}
```