输入一个字符判断是小写字母还是大写字母C语言
时间: 2023-11-04 18:04:37 浏览: 42
使用C语言的isupper()和islower()函数可以判断一个字符是大写字母还是小写字母,例如:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char c = 'A';
if (isupper(c)) {
printf("%c is an uppercase letter.\n", c);
} else if (islower(c)) {
printf("%c is a lowercase letter.\n", c);
} else {
printf("%c is not a letter.\n", c);
}
return 0;
}
```
输出:
```
A is an uppercase letter.
```
相关问题
用c语言输入一个字符判断大写字母还是小写字母或者是数字
可以使用 C 语言中的 `isupper()`、`islower()` 和 `isdigit()` 函数来判断一个字符是大写字母、小写字母还是数字。以下是一个示例程序:
```
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
printf("请输入一个字符:\n");
scanf("%c", &ch);
if (isupper(ch)) {
printf("%c 是大写字母。\n", ch);
} else if (islower(ch)) {
printf("%c 是小写字母。\n", ch);
} else if (isdigit(ch)) {
printf("%c 是数字。\n", ch);
} else {
printf("%c 不是字母或数字。\n", ch);
}
return 0;
}
```
在上面的程序中,`isupper()`、`islower()` 和 `isdigit()` 分别用于判断一个字符是否是大写字母、小写字母和数字。当输入的字符不是字母或数字时,会输出相应的提示信息。
c语言输入一个字符判断该字符是大写还是小写
以下是一个简单的C程序,可以输入一个字符并判断它是大写字母还是小写字母:
```c
#include <stdio.h>
int main() {
char c;
printf("请输入一个字符:");
scanf("%c", &c);
if (c >= 'A' && c <= 'Z') {
printf("输入的字符是大写字母\n");
} else if (c >= 'a' && c <= 'z') {
printf("输入的字符是小写字母\n");
} else {
printf("输入的字符不是字母\n");
}
return 0;
}
```
该程序首先提示用户输入一个字符,然后使用`scanf()`函数读取输入的字符并将其存储在变量`c`中。接下来,使用`if...else`语句根据输入的字符的ASCII码值判断它是大写字母、小写字母还是其他字符,并输出相应的结果。注意,大写字母的ASCII码值范围是65到90,小写字母的ASCII码值范围是97到122。