|
|

楼主 |
发表于 2012-7-23 17:16:32
|
显示全部楼层
补上代码- #include <stdio.h>
- void main()
- {
- int c,i,num[10]={0},blank=0,other=0;
- while ((c = getchar()) != EOF)
- {
- if(c >='0' && c<='9')
- {
- switch(c)
- {
- case '0': num[0]++;break;
- case '1': num[1]++;break;
- case '2': num[2]++;break;
- case '3': num[3]++;break;
- case '4': num[4]++;break;
- case '5': num[5]++;break;
- case '6': num[6]++;break;
- case '7': num[7]++;break;
- case '8': num[8]++;break;
- case '9': num[9]++;break;
- }
- }
- else if(c==' ' || c=='\n' || c=='\t')
- {
- blank ++;
- }
- else
- {
- other ++;
- }
- }
- for (i=0; i<10; i++)
- {
- printf("数字%d的个数为%d\n",i,num[i]);
- }
- printf("\n空格符的个数为%d\n其他字符的个数为%d",blank,other);
- }
复制代码 |
|