char * multiply(char * num1, char * num2){ if(*num1=='0' || *num2=='0') return "0"; int i, j, len1=strlen(num1), len2=strlen(num2),temp, pst=(len1+len2)*2-1, cur; char* s=(char*)calloc((len1+len2)*2+1,sizeof(char)); memset(s,0x30,(len1+len2)*2); for(j=len2-1; j>=0; j--){ for(i=len1-1; i>=0; i--){ cur=(len1-1-i)+(len2-1-j); temp= (num2[j]-'0')*(num1[i]-'0'); s[pst-cur-1]+= (s[pst-cur]-'0'+ temp%10)>=10?1 :0; s[pst-cur] = (s[pst-cur]-'0'+ temp%10)%10 +'0'; s[pst-cur-2]+= ((s[pst-cur-1]-'0'+ temp / 10)>=10)?1 :0; s[pst-cur-1]= (s[pst-cur-1]-'0' + temp/10)%10 + '0'; } } while(s[pst-cur-2]=='0') cur--; return s+pst-cur-2; }