這個(gè)用數(shù)組的方式來(lái)實(shí)現(xiàn)比較好,包括后面的輸出
#include<stdio.h>#include<stdlib.h>main(){intN,n,b,i,c[]={1,2,3,4,5,6,7,8,9},d[9]={0};intr=0;printf("Pleaseenterthenumber:\n");scanf("%d",&n);N=n;n=abs(n);while(n>0){b=n%10;for(i=0;i<9;i++){if(b==c[i])d[i]++;}n=n/10;r++;}printf("%d:%dbits\n",N,r);for(i=0;i<9;i++){if(d[i]!=0)printf("%d:%d\n",c[i],d[i]);}system("pause");}