1.6 数组

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

 1 #include<stdio.h>
 2 int main()
 3 {
 4     int c, i, nwhite, nother;
 5     int ndigit[10];
 6 
 7     nwhite = nother = 0;
 8     for (i = 0; i < 10; i++)
 9         ndigit[i] = 0;
10 
11     while ((c = getchar()) != EOF)
12     {
13         if (c >= '0'&& c <= '9')
14         {
15             ndigit[c - '0']++;
16         }
17         else if (c == ' ' || c == '\t' || c == '\n')
18         {
19             nwhite++;
20         }
21         else
22         {
23             nother++;
24         }
25     }
26     printf("digits =");
27     for (i = 0; i < 10; i++)
28     {
29         printf(" %d", ndigit[i]);
30     }
31     printf(", nwhite space = %d, other = %d\n", nwhite, nother);
32     return 0;
33 }

 

你可能感兴趣的:(1.6 数组)