回复 9楼 幸运之星
你的算法用在这里大材小用了。用你的算法可以做这个题了
2+22+222+2222+22222+2....2(n个2)
# include <stdio.h> unsigned long huan(int i) { int j,n=1,y; unsigned long x; x=y=i; while(x/10!=0) { n++; x=(x-x%10)/10; } x=y; for(j=0;j<n;j++) x*=10; x+=y; return x; } main() { unsigned long x,n=0; int i,y; scanf("%ld",&y); for(i=1;i<=y;i++) { x=huan(i); n+=x; printf("%ld",x); if(i!=y)printf("+"); if(i%10==0)printf("\n"); } printf("=%ld\n",n); getch(); }