编写c程序,将输入的大写字符转换为小写字符
时间: 2023-05-11 15:03:14 浏览: 46
可以使用C语言中的tolower()函数将大写字符转换为小写字符,以下是示例代码:
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
printf("请输入一个大写字母:");
scanf("%c", &c);
if(isupper(c)) {
c = tolower(c);
printf("转换后的小写字母为:%c\n", c);
} else {
printf("输入的不是大写字母!\n");
}
return 0;
}
输入一个大写字母后,程序会将其转换为小写字母并输出。
相关问题
编写程序,将输入的大写字符转换为小写字符。
可以使用以下代码实现:
```
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
while ((c = getchar()) != EOF) {
putchar(tolower(c));
}
return 0;
}
```
这个程序会读取输入的字符,如果是大写字母就将其转换为小写字母并输出,直到读取到文件结束符为止。
C语言编写程序,将字符串中小写字母字符转换为大写。
以下是一个简单的C程序,可以将字符串中的小写字母全部转换为大写字母:
```c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[1000];
printf("请输入字符串:");
fgets(str, sizeof(str), stdin); // 从标准输入读取字符串
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (islower(str[i])) { // 判断是否为小写字母
str[i] = toupper(str[i]); // 将小写字母转换为大写字母
}
}
printf("转换后的字符串为:%s", str);
return 0;
}
```
这个程序首先从标准输入读取一个字符串,然后遍历字符串的每一个字符,如果发现是小写字母,就使用 `toupper()` 函数将它转换为大写字母。最后输出转换后的字符串。