问题及代码:
/*
Copyright (c) 2016,烟台大学计算机与控制工程学院
All Rights Reserved.
文件名称:统计出其中英文字母、数字、空格和其他字符的个数
作 者:胡寅生
完成日期:2016年10月27日
版 本 号;v1.0
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
int alpha=0,number=0,space=0,other=0;
while ((ch=getchar())!='\n')
{
if ((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
alpha++;
else if (ch>='0'&&ch<='9')
number++;
else if (ch==' ')
space++;
else
other++;
}
printf("%d %d %d %d",alpha,number,space,other);
return 0;
}
运行结果:
学习心得:注意分号的使用