Multiplication by parallel arrays

I'm working on a program that takes two large numbers, stored in arrays of integers (one digit of the number per location) and performs multiplication to get their product in another array. My code gives an answer and some of the answers seem right and some don't. I wanted to post on here hoping that someone might can see why some of my answers are incorrect.

Here is the function that multiplies the arrays together:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void getProduct (int top[], int bottom[], int product[])
{
    for (int k = (MAX - 1); k > 0; k--)
    {
        for (int i = (MAX - 1); i > 0; i--)
        {
            product[i] = bottom[k] * top[i] + product[i];
                
            if (product[i] > 9)
            {
                product[i - 1] = product[i] / 10;
                product[i] = product[i] % 10;
            }
        }
    }
}


And here is the output that I am getting. This output has been formatted.

 6                                                           
x9                                                           
--
54                                                          

 46123                                                       
x85321                                                       
------
374987                                                      

 3872663123                                                  
    x654321                                                      
-----------
23235983743                                                 

 222222222222222222222222222222                              
x555555555556666666666666666666                              
--------------------------------
33403333333333333333333333333340                            

 999999999999999999999999999999                              
x999999999999999999999999999999                              
--------------------------------
99919999999999999999999999999991                            

 999999999999999999999999999999                              
                             x3                                                           
--------------------------------
99979999999999999999999999999997                            

 876876876876876876876876876876                              
                x58485949392039                                              
--------------------------------
43884384384384384384384384384388  


And here is the code that formats and displays the output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//Print out the multiplication problem in readable format.
void printOut (int top[], int bottom[], int product[], int t_NUM, int b_NUM, int p_NUM)
{
    shiftLeft (top, t_NUM);
    shiftLeft (bottom, b_NUM);
    shiftLeft (product, p_NUM);
    
    cout << " ";
    printAry (top, t_NUM);              //Print top factor.
    
    cout << endl;
    for (int i = 0; i < (t_NUM - b_NUM); i++)
    {
        cout << " ";
    }
    
    cout << "x";                //Print multiplication symbol.
    printAry (bottom, b_NUM);           //Print bottom factor.
    
    cout << endl;
    for (int i = 0; i < p_NUM; i++)     //Print line.
    {
        cout << "-";
    }
    
    cout << endl;
    printAry (product, p_NUM);          //Print factor.
}


void printAry (int ary[], int NUM)
{
    for (int i = 0; i < MAX; i++)
    {
        if (ary[i] == 0 && i >= NUM)
        {
            cout << " ";
        }
        else
        {
            cout << ary[i];
        }
    }
}
Only thing I can think of is that maybe the product array is too small for the whole output? I'm honestly not too sure if that is the case.
I don't think that's it. The product array has 60 elements.

I'm pretty sure my problem has something to do with not accounting for the way it needs to perform the multiplication.

For example, when you multiply numbers like this on paper you have something like

1234
x 56
------
####
####0

What I'm needing is a way to account for those 0's and I can't figure out how.
In your print statement, the condition for the for-loop should be i < NUM?
Topic archived. No new replies allowed.