统计数字小程序

#include<stdio.h>
main()
{
    int c,i,nwhilte,nother;
    int ndigit[10];
    nwhilte=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')
        ++nwhilte;
        else ++nother;
       
       
    }
    printf("空白字符%d 其它%d \n",nwhilte,nother);
    for(i=0;i<10;i++)
        printf("%d",ndigit[i]);
}

附:C语言函数库输入输出流:http://www.cppreference.com/wiki/c/io/start

posted @ 2009-06-24 00:38  macula7  阅读(222)  评论(0编辑  收藏  举报