c语言大写字母a变小写a代码
时间: 2023-09-09 08:07:58 浏览: 336
将大写字母转换为小写字母的方法是将其ASCII码值加上32。因此,将字符'a'的ASCII码值减去'A'的ASCII码值再加上'a'的ASCII码值,即可将大写字母A转换为小写字母a。以下是C语言代码示例:
```c
char ch = 'A';
if (ch >= 'A' && ch <= 'Z') {
ch = ch - 'A' + 'a';
}
printf("%c", ch); // 输出 'a'
```
在上述代码中,如果字符ch是大写字母,则将其转换为小写字母后输出。
相关问题
c语言大写字母转换成小写字母
可以使用C语言中的toupper()函数将字符串中的小写字母转换成大写字母。具体实现方法如下:
1. 首先需要包含头文件<ctype.h>。
2. 使用toupper()函数将字符串中的小写字母转换成大写字母。
3. 遍历字符串中的每个字符,判断是否为小写字母,如果是,则使用toupper()函数将其转换成大写字母。
4. 最后输出转换后的字符串。
示例代码如下:
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[100];
int i;
printf("请输入一个字符串:");
gets(str);
for(i=; str[i]!='\'; i++)
{
if(islower(str[i]))
{
str[i] = toupper(str[i]);
}
}
printf("转换后的字符串为:%s", str);
return ;
}
c语言 大写字母转换成小写字母
在 C 语言中,可以使用标准库函数 `tolower()` 将大写字母转换成小写字母。该函数的原型为:
```c
int tolower(int c);
```
其中,参数 `c` 是要转换的字符,返回值是转换后的字符。
下面是一个示例程序,将输入的字符串中的大写字母转换成小写字母:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
int i;
printf("Enter a string: ");
scanf("%[^\n]", str);
for (i = 0; str[i] != '\0'; i++) {
if (isupper(str[i])) {
str[i] = tolower(str[i]);
}
}
printf("The string in lowercase is: %s\n", str);
return 0;
}
```
在上面的程序中,首先使用 `scanf()` 函数读取输入的字符串,然后使用 `isupper()` 函数判断每个字符是否为大写字母,如果是,则使用 `tolower()` 函数将其转换成小写字母。最后,使用 `printf()` 函数输出转换后的字符串。