编写c语言代码通过键盘输入字符,将输入的字符分为控制、数字、大写字母、小写字母和其他字符等五类。 **输入格式要求:"%c" 提示信息:"Enter a charactor:" **输出格式要求:"\nThe charactor is a control charactor.\n" "\nThe charactor is a digit charactor.\n" "\nThe charactor is a capital charactor.\n" "\nThe charactor is a lower charactor.\n" "\nThe charactor is a other charactor.\n" 程序运行示例1如下: Enter a charactor:1 The charactor is a digit charactor. 程序运行示例2如下: Enter a charactor:a The charactor is a lower charactor.
时间: 2023-07-07 11:45:54 浏览: 87
c语言将字符串中的小写字母转换成大写字母
5星 · 资源好评率100%
下面是满足要求的C语言代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if (iscntrl(c)) {
printf("\nThe character is a control character.\n");
} else if (isdigit(c)) {
printf("\nThe character is a digit character.\n");
} else if (isupper(c)) {
printf("\nThe character is a capital character.\n");
} else if (islower(c)) {
printf("\nThe character is a lower character.\n");
} else {
printf("\nThe character is an other character.\n");
}
return 0;
}
```
程序通过 `scanf` 函数读取用户输入的字符,并通过 `iscntrl`、`isdigit`、`isupper` 和 `islower` 函数判断该字符属于哪一类。最后,程序根据判断结果输出相应的提示信息。
阅读全文