输入一行字符,分别统计数字,大写字母,小写字母和其他字符的个数用c语言写
时间: 2023-06-18 20:06:42 浏览: 82
```c
#include <stdio.h>
int main() {
char str[100];
int digits = 0, uppercase_letters = 0, lowercase_letters = 0, others = 0;
printf("请输入一行字符:");
fgets(str, 100, stdin); // 从标准输入读取一行字符
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] >= '0' && str[i] <= '9') {
digits++;
} else if (str[i] >= 'A' && str[i] <= 'Z') {
uppercase_letters++;
} else if (str[i] >= 'a' && str[i] <= 'z') {
lowercase_letters++;
} else {
others++;
}
}
printf("数字:%d\n", digits);
printf("大写字母:%d\n", uppercase_letters);
printf("小写字母:%d\n", lowercase_letters);
printf("其他字符:%d\n", others);
return 0;
}
```
阅读全文