Do school mathematics , compute difference of current digits and carry
int sub = ( ( str1 [ i + diff ] - '0' ) - ( str2 [ i ] - '0' ) - carry ) ; if ( sub < 0 ) { sub = sub + 10 ; carry = 1 ; } else carry = 0 ; str . push_back ( sub + '0' ) ; }