c语言编程题1. 编程从键盘输入一个大写字母,将其转换为小写英文字母,并将转换前后
时间: 2023-09-19 20:03:33 浏览: 545
可以使用C语言的函数toupper()和tolower()来实现将大写字母转换为小写字母的功能。具体的程序如下:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char uppercase, lowercase;
printf("请输入一个大写字母:");
scanf("%c", &uppercase);
lowercase = tolower(uppercase);
printf("转换后的小写字母为:%c\n", lowercase);
printf("转换前的大写字母为:%c\n", uppercase);
return 0;
}
```
在程序中,首先定义了两个字符变量uppercase和lowercase,分别用于存储输入的大写字母和转换后的小写字母。然后使用scanf()函数从键盘输入一个大写字母,并将其存储到uppercase变量中。接下来使用tolower()函数将大写字母转换为小写字母,并将转换后的结果存储到lowercase变量中。最后,使用printf()函数分别输出转换后的小写字母和转换前的大写字母。
例如,如果用户输入的大写字母为'A',则程序将输出:
转换后的小写字母为:a
转换前的大写字母为:A
相关问题
从键盘上任意输入一个大写字母,用C语言编程实现将大写 字母转换为小写字母后输出
可以使用C语言中的tolower函数将大写字母转换为小写字母,代码如下:
```c
#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;
}
```
输入一个大写字母后,程序会将其转换为小写字母并输出。如果输入的不是大写字母,则会提示输入错误。
从键盘输入一个大写英文字母,将其转换为小写字母后,再显示到屏幕上C语言
实现:
```c
#include <stdio.h>
int main() {
char ch;
printf("请输入一个大写英文字母:");
scanf("%c", &ch);
ch += 32; // 将大写字母转换为小写字母
printf("转换后的小写字母为:%c", ch);
return 0;
}
```
运行结果示例:
```
请输入一个大写英文字母:H
转换后的小写字母为:h
```