#include #include void add(char d1[],char d2[],char sum[]){ int i,j,carry=0,inx,idx1,idx2,t; inx=0; idx1=strlen(d1)-1; idx2=strlen(d2)-1; carry=0; while(idx1>=0&&idx2>=0) { sum[inx++]=(d1[idx1]-'0'+d2[idx2]-'0'+carry)%10+'0'; carry=(d1[idx1]-'0'+d2[idx2]-'0'+carry)/10; idx1--,idx2--; } while(idx1>=0) { sum[inx++]=(d1[idx1]-'0'+carry)%10+'0'; carry=(d1[idx1]-'0'+carry)/10; idx1--; } while(idx2>=0) { sum[inx++]=(d2[idx2]-'0'+carry)%10+'0'; carry=(d2[idx2]-'0'+carry)/10; idx2--; } while(carry>0) { sum[inx++]=carry%10+'0'; carry=carry/10; } sum[inx]='\0'; for(i=0,j=strlen(sum)-1;i 0) { if(strlen(sum)==0) { strcpy(sum,ch); } else { strcpy(data,sum); add(data,ch,sum); } } } if(strlen(sum)==0) strcpy(sum,"0"); printf("%s\n",sum); if(n!=0)//注意格式 printf("\n"); } }