Multiplication using two characters array of size 40!

Hello, i am developing a program which should multiply two character arrays of length of 40 treating as signed numbers for example:

char arr[4] = {'-', '1','2','\0'}; is equivalent to -123 in integer form.

now i have this in 40 size of array and i have two arrays . What will be the algorithm that should i employ? i can't find the way to implement this.

Same goes for Division, +1 if some one hints me about 40bit numbers division.

Thank you!
Last edited on
The same way as in elementary school. For example, 45*67 involves:
a = 7*5
b = 7*4
c = 6*5
d = 6*4

There is adding up of these results too. We know that the least significant digit of the result will be:
r0 = a_lo = a % 10

If there any excess, it will be carried over to next digits:
a_hi = a / 10
sum = b_lo + c_lo + a_hi
r1 = sum % 10

And so forth.

Multiplication is "right-to-left". Division is "left-to-right" and more complex. In fact, it might have to use the multiplication as helper.
Use long multiplication:
1
2
3
4
5
6
7
char num1[] = "-123";
char num2[] = "20";

char* result = mult(num1, num2);
 -123
   20
 −−−−
  000
 246
 −−−−
-2460
start traversing your arrays from the end and multiply each digits handling carryover digits.
Topic archived. No new replies allowed.