方法1: main( ) { long a,b,c,d,e,x; scanf("%ld",&x); a=x/10000;/*分解出萬位*/ b=x%10000/1000;/*分解出千位*/ c=x%1000/100;/*分解出百位*/ d=x%100/10;/*分解出十位*/ e=x%10;/*分解出個位*/ if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld ",e,d,c,b,a); else if (b!=0) printf("there are 4, %ld %ld %ld %ld ",e,d,c,b); else if (c!=0) printf(" there are 3,%ld %ld %ld ",e,d,c); else if (d!=0) printf("there are 2, %ld %ld ",e,d); else if (e!=0) printf(" there are 1,%ld ",e); } 方法2: main() { int a,b,i,j,n=1,t,s[6]; scanf("%d",&a); b=a; while(b/10>0) { n++; b=b/10; } for(i=n;i>=1;i--) { t=1; for(j=1;j<n;j++) {t=t*10;} s[i]=a/t; } for(i=1;i<=n-1;i++) s[i]=s[i]-s[i-1]*10; printf("%d",s[i]); } 歡迎經常探討此類問題!
方法1: main( ) { long a,b,c,d,e,x; scanf("%ld",&x); a=x/10000;/*分解出萬位*/ b=x%10000/1000;/*分解出千位*/ c=x%1000/100;/*分解出百位*/ d=x%100/10;/*分解出十位*/ e=x%10;/*分解出個位*/ if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld ",e,d,c,b,a); else if (b!=0) printf("there are 4, %ld %ld %ld %ld ",e,d,c,b); else if (c!=0) printf(" there are 3,%ld %ld %ld ",e,d,c); else if (d!=0) printf("there are 2, %ld %ld ",e,d); else if (e!=0) printf(" there are 1,%ld ",e); } 方法2: main() { int a,b,i,j,n=1,t,s[6]; scanf("%d",&a); b=a; while(b/10>0) { n++; b=b/10; } for(i=n;i>=1;i--) { t=1; for(j=1;j<n;j++) {t=t*10;} s[i]=a/t; } for(i=1;i<=n-1;i++) s[i]=s[i]-s[i-1]*10; printf("%d",s[i]); } 歡迎經常探討此類問題!