- 题目
- 代码
- 其他
编写一个程序,程序的功能是从键盘上读入一行字符(以#为结束字符),分别统计出英文字符、数字、
空格以及其他字符的个数。
#include其他#include int main() { int eng=0,num=0,space=0,other=0; char s[100]= {' '}; gets(s); for(int i=0; s[i]!='#'; i++) { if((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<='z')) eng++; else if(s[i]>='0'&&s[i]<='9') num++; else if(s[i]==' ') space++; else other++; } printf("%d %d %d %d",eng,num,space,other); return 0; }
代码没有分别统计大写字母和小写字母,如果需要,可以把if里的条件拆成两个。



