问题及代码:
/*用swich语句统计数字、字符和其它符号*/
#include<stdio.h>
int main()
{
int c,i,nwhite,ndigit[10],nother;
for(i=0;i<10;i++)
ndigit[i]=0;
while((c=getchar())!=EOF)
{
swich(c)
{
case '0':
case '1':
case '2':
case '9':
ndigit[c-'0']++;
break;
case ' ':
case '\t':
case '\b':
nwhite++;
break;
default:
nother++
break;
}
}
for(i=0;i<10;i++)
printf("出现的数字为%d",ndigit[i]);
printf("出现的空字符有%d,出现的其它字符有%d\n",nwhite,nother);
return 0;
}