C语言程序:统计字符类型个数
#include<stdio.h>
int main() {
char ch;
int letter = 0, space = 0, other = 0;
printf('请输入一行字符,直到输入 $ 结束:
');
while ((ch = getchar()) != '$') {
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
letter++;
} else if (ch == ' ') {
space++;
} else {
other++;
}
}
printf('英文字母个数:%d
空格个数:%d
其他字符个数:%d
', letter, space, other);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/na2p 著作权归作者所有。请勿转载和采集!