输入是一串以换行结束的任意字符,应如何统计其中0-9每个数字的个数?
#include <stdio.h>
int main()
{
char ch = 0;
int i;
int a[10] = {0};
while (ch != '\n')
{
scanf("%c", &ch);
if (ch >= '0' && ch <= '9')
{
a[ch- '0']++;
}
}
for (i = 0; i < 10; i++)
printf("%d出?现?次ä?数ºy:êo%d\n", i, a[i]);
}