在turboC3.0下运行的
#include<stdio.h>
#define N 10
#define M 100
int main(void)
{
int b[N]={0},j=0;
char a[M];
while((a[j]=getchar())!='\n')
{
switch(a[j])
{
case '0':b[0]++;break;
case '1':b[1]++;break;
case '2':b[2]++;break;
case '3':b[3]++;break;
case '4':b[4]++;break;
case '5':b[5]++;break;
case '6':b[6]++;break;
case '7':b[7]++;break;
case '8':b[8]++;break;
case '9':b[9]++;break;
default :j++;
}
}
for(j=0;j<N;j++)
printf("%d=>%d\n",j,b[j]);
return 0;
}
我验证了,结果正确.