444,246 Members | 1,515 Online
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

# multiplication of long integers

 P: 10 Hi, Im doing a multiplication of two large integers which are store in arrays(such as 2345 is in array as 2 in a[0], 3 in a[1] and so on)like this im storing integers in two arrays.The logic i have used is explained with code below, Expand|Select|Wrap|Line Numbers class large{     int no[SIZE];    //array is used to store the large number. Each digit of a the number is stored as an element..                     // 123 is stored as no[3]={1,2,3} public:        large operator *(large& x){ // overload the * operator /*         34 x 46         -------           204            // these values are stored in the          136            // two dimensional array mat[][];         -------          1564   // this the value stored in "large ret" */                                         large ret;                         int carry=0;         int mat[2*SIZE+1][2*SIZE]={0};         for(int i=SIZE-1;i>=0;i--){             for(int j=SIZE-1;j>=0;j--){                 carry += no[i]*x.no[j];                 if(carry < 10){                     mat[i][j-(SIZE-1-i)]=carry;                     carry=0;                 }                 else{                 mat[i][j-(SIZE-1-i)]=carry%10;                     carry=carry/10;                 }             }         }         for( i=1;i=0;j--){                 carry += mat[i][j]+mat[i-1][j];                 if(carry < 10){                     mat[i][j]=carry;                     carry=0;                 }                 else{                     mat[i][j]=carry%10;                     carry=carry/10;                 }             }         }         for( i=0;i=0;i--,index--){             no[index]=_no[i]-'0';         }     }     void print(){        //print the large number         int start=0;         for(int i=0;i