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

来源:互联网 发布:js获取flv的帧图片 编辑:程序博客网 时间:2024/05/21 00:15
#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);
}
阅读全文
0 0
原创粉丝点击