用C语言写一个小写字母转大写字母的程序
时间: 2023-04-01 07:04:41 浏览: 378
您好,以下是用 C 语言编写小写字母转大写字母的程序:
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
printf("请输入一个小写字母:");
scanf("%c", &c);
if(islower(c)) {
c = toupper(c);
printf("转换后的大写字母为:%c\n", c);
} else {
printf("您输入的不是小写字母!\n");
}
return ;
}
希望能对您有所帮助!
相关问题
用c语言写一个用c语言写一个小写字母转换为大写字母的函数
可以使用C语言中的字符处理函数`toupper()`实现小写字母转换为大写字母的功能。以下是一个简单的示例函数:
```c
#include <ctype.h>
void toUpper(char *str) {
int i = 0;
while (str[i]) {
str[i] = toupper(str[i]);
i++;
}
}
```
该函数接受一个指向字符串的指针作为参数,并将其中的小写字母转换为大写字母。可以使用以下代码来测试该函数:
```c
#include <stdio.h>
int main() {
char str[] = "Hello, World!";
printf("Original string: %s\n", str);
toUpper(str);
printf("Modified string: %s\n", str);
return 0;
}
```
输出结果为:
```
Original string: Hello, World!
Modified string: HELLO, WORLD!
```
用c语言写一个程序使小写字母变成大写字母
好的,以下是使用C语言编写的将小写字母转换为大写字母的程序:
```
#include <stdio.h>
int main() {
char ch;
printf("请输入一个小写字母:");
scanf("%c", &ch);
if (ch >= 'a' && ch <= 'z') {
ch = ch - 32; // 将小写字母转换为大写字母
printf("转换后的大写字母为:%c\n", ch);
} else {
printf("输入的不是小写字母!\n");
}
return 0;
}
```
程序的思路是首先读入一个字符,然后判断这个字符是否为小写字母,如果是,就将其转换为大写字母并输出;如果不是,就提示用户输入的不是小写字母。在ASCII码表中,小写字母a到z的ASCII码值是97到122,而对应的大写字母A到Z的ASCII码值是65到90,因此将小写字母转换为大写字母的方法是将其ASCII码值减去32。
相关推荐
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)