1021 个位数统计,C

#include <stdio.h>

int main()
{
	char a[1000] = {0};
	int n,i,x;
	scanf("%s",a);
	
	for(i=0; i<=9; i++)	//从0到9依次检查有几个,并输出
	{	
		n=0;x=0;
		while( a[n] )
		{
			if( (a[n]-'0') == i )	x++;	
			n++;
		}
		if(x)	
        {  
            printf("%d:%d",i,x);
		    if(i != 9)	printf("\n");
        }
	}

	return 0;
}
发布了44 篇原创文章 · 获赞 0 · 访问量 884

猜你喜欢

转载自blog.csdn.net/weixin_43916400/article/details/104398179