How do I multiply two arrays? Assuming that the numbers in the arrays are all single digit integers, which makes the array a big integer. Now I want to multiply these two big integers formed from arrays and also at the same time display steps.

Please don't use multidimensional arrays but if it is the only way, then please explain a bit. I really want to understand this stuff.


The following is the example I wrote till now.

#include <iostream>

using namespace std;

int main ()
    {
     
     int indexOne, indexTwo = 5, tempValOne, tempValTwo, tempValThree, carry, result, outPut;
     
     int multiplicand[1] = {4};
         
     int multiplier[1] = {4};
     
     
     for(indexOne = 0; indexOne >= 0; indexOne --)
     {
        tempValOne = multiplier[indexOne];
        
        while(tempValOne >= 0)
         {
           tempValThree += tempValTwo;
           
           tempValOne --;
           
         }
    
     }
     
     cout << tempValThree << endl;
        // change color to green as this will be don now 
     
     /*for(indexOne = 5; indexOne >= 0; indexOne--)
     {
     multiplicand[indexOne] = tempValOne + carry;
     
     multiplier[indexTwo] = tempValTwo;
     
    
         
     result = tempValOne * tempValTwo;
     
     outPut = result % 10;
     
     carry = result / 10;
     
     //cout << outPut << endl;
     
     cout << result << endl;
     }
     */
 
       
         
    system ("PAUSE");
    
    return 0;        
         
    }

You access each individual numbers and multiply them :

int Array[2] = {1,1};
int Array2[2] = {5,5};
int result[2] = {};
result[0] = Array[0]*Array2[0];
result[1] = Array[1]*Array2[1];

Of course there is a lot more to this, but you get the basic idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.