Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void multiply( int multiplicand[], int multiplier[], int product[],int multiplicandSize, int multiplierSize, int &productSize )
- {
- memset(product, 0, arraySize*sizeof(int));
- for( int i = 0; i < multiplicandSize; i++ ) // 先乘
- for( int j = 0; j < multiplierSize; j++ )
- product[i+j] += multiplicand[i] * multiplier[j];
- for( int i = 0; i < multiplicandSize + multiplierSize; i++ ) // 進位
- {
- if( product[i] > 9 )
- {
- product[i+1] += product[i] / 10;
- product[i] %= 10;
- }
- }
- productSize = multiplicandSize + multiplierSize; // 算size
- if( product[productSize-1] == 0 )
- productSize -= 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement