Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Arithmetic operation of data structure long integer
Arithmetic operation of data structure long integer
Give a basic idea, and realize high-precision calculation with array. Each data in the array stores one digit, and bit-by-bit calculation and division are troublesome.

Create three arrays, two for the data to be calculated and one for the result.

The input data should be obtained by character type first, then processed into a number and stored in the corresponding position of the array.

Addition starts from the last bit of two arrays, carry is included in the previous bit, and subtraction is similar. Pay attention to borrowing.

Multiplication requires a double loop. Multiplies each bit of the first array with each bit of the second array. Note that the I bit of the second array is multiplied by the j bit of the first array, and the result will be written into the i+j- 1 bit of the result array. At the same time, carry calculation should be done well (it can be processed at one time after calculation).