请用c语言完成以下编程题编程从键盘输入若干字符直到输入字符为止统计其中的字母字符、数字字符、空格符及其他字符的个数并输出统计结果。 例如: 输入:This is the 1s time i am here 输出: 字母字符21数字字符1空格7其他2
#include <stdio.h>
int main()
{
char c;
int letter = 0, digit = 0, space = 0, other = 0;
printf("请输入若干字符,以*结束:\n");
while ((c = getchar()) != '*') {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
letter++;
} else if (c >= '0' && c <= '9') {
digit++;
} else if (c == ' ') {
space++;
} else {
other++;
}
}
printf("字母字符:%d,数字字符:%d,空格:%d,其他:%d\n", letter, digit, space, other);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/bpR7 著作权归作者所有。请勿转载和采集!