输入一串数字统计0到9每个数字的个数

题目:
输入一串字符统计这串字符中0有多少,1有多少,…,9有多少。

#include <stdio.h>
int main()
{
	char c;
	int shu[10]={0},i;
	while((c=getchar())!='\n')
	{
		if(c>='0'&&c<='9')
			shu[c-'0']++;
	}
	for(i=0;i<=9;i++)
		printf("%d有%d个\n",i,shu[i]);
}

猜你喜欢

转载自blog.csdn.net/mishilq/article/details/83500072