您的位置:首页 > 其它

编写一个程序统计各个数字、空白符(包括空格符、制表符及换行符)以及其它字符出现的次数

2017-10-19 22:06 519 查看
#include<stdio.h>

/*count digits,white space,others*/

main()

{
int c, i, nwhite, nother;
int ndigit[10];

nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;

while ((c = getchar()) != EOF)
if (c >= '0'&&c <= '9')
++ndigit[c - '0'];
else if (c == ' ' || c == '\n' || c == '\t')
++nwhite;
else
++nother;

printf("digits=");
for (i = 0; i < 10, ++i)
printf(|" %d", ndigit[i]);
printf(",white space= %d,other=%\n",
nwhite, nother);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  统计空白符
相关文章推荐