统计各个数字 空白符 所有其他字符出现的次数

#include <stdio.h>
/*统计各个数字、空白符(空格,制表符,换行)、所有其他字符出现的次数*/
int main()
{
    int count[10], i;//各个数字出现的次数
    int spaceN = 0;//空白符出现的次数
    int otherN = 0;//其他字符出现的次数
    char c;//存放字符
    for(i=0; i <= 9; i++)
        count[i] = 0;
    while((c = getchar()) != EOF){
        if(c >= '0' && c <= '9' ){
            count[c-'0']++;
        }
        else if(c == ' ' || c == '\n' || c == '\t')
            spaceN++;
        else
            otherN++;
    }
    for(i = 0; i < 10; i++)
        printf("数字 %d 出现的次数:%d\n", i, count[i]);
    printf("空白符出现的次数:%d\n", spaceN);
    printf("其他字符出现的次数%d\n", otherN);
    return 0;
}
 

猜你喜欢

转载自blog.csdn.net/yjysunshine/article/details/81192644