用C语言写一个将大写字母改成小写字母的程序
时间: 2023-04-02 20:05:02 浏览: 63
你好,以下是回答:
#include <stdio.h>
int main() {
char c;
printf("请输入一个大写字母:");
scanf("%c", &c);
if (c >= 'A' && c <= 'Z') {
c = c + 32;
printf("转换后的小写字母为:%c\n", c);
} else {
printf("输入的不是大写字母!\n");
}
return ;
}
相关问题
用C语言写将字符串中所有的大写字母改成小写字母。
可以使用C语言中的字符处理函数`tolower()`将大写字母转换为小写字母,然后遍历字符串中的每个字符,判断是否为大写字母,若是则调用`tolower()`进行转换。下面是一个示例代码:
```c
#include <stdio.h>
#include <ctype.h> // 包含tolower()函数的头文件
void toLower(char* str) {
int i = 0;
while (str[i] != '\0') {
if (isupper(str[i])) { // 判断是否为大写字母
str[i] = tolower(str[i]); // 转换为小写字母
}
i++;
}
}
int main() {
char str[] = "Hello, WORLD!";
printf("Before conversion: %s\n", str);
toLower(str);
printf("After conversion: %s\n", str);
return 0;
}
```
运行结果为:
```
Before conversion: Hello, WORLD!
After conversion: hello, world!
```
c语音程序将大写字母改成小写字母
你可以使用C语言中的字符串函数 `tolower()` 将大写字母转换成小写字母。
以下是一个示例代码:
```c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main() {
char str[100];
printf("请输入字符串:");
fgets(str, sizeof(str), stdin);
for (int i = 0; i < strlen(str); i++) {
if (isupper(str[i])) {
str[i] = tolower(str[i]);
}
}
printf("转换后的字符串为:%s", str);
return 0;
}
```
这个程序首先使用 `fgets()` 函数获取用户输入的字符串,并使用 `strlen()` 函数获取字符串长度。然后,程序遍历整个字符串,如果当前字符是大写字母,则使用 `tolower()` 函数将其转换为小写字母。最后,程序输出转换后的字符串。