引用自网站:http://blog.csdn.net/liu_yanzhao/article/details/52423987
代码:
#include<stdio.h>
int main()
{
int char_num = 0, int_num = 0, space_num = 0, other_num = 0;
char ch;
while ((ch = getchar()) != '
')
{
if (ch <= 'z'&&ch >= 'a' || ch <= 'Z'&&ch >= 'A')
{
char_num++;
}
else if (ch <= '9'&&ch >= '0')
{
int_num++;
}
else if (ch == ' ')
{
space_num++;
}
else
{
other_num++;
}
}
printf("字母个数:%d
", char_num);
printf("数字个数:%d
", int_num);
printf("空格个数:%d
", space_num);
printf("其他个数:%d
", other_num);
}
实现功能:对输入的字符进行数目统计。