vendredi 1 mars 2019

Adding 2d Array to 1d Array

I have this function that should add the 2d array to 1d array.

`void AddTab(int **tab,int n,int m)
{
    int *temp_tab=new int[m];
    memset(temp_tab, 0, sizeof(temp_tab));
    for (int i=0;i<m;i++)
    {
    for (int j=0;j<n;j++)
    {
        temp_tab[j] += tab[i][j];
        cout << temp_tab[j] << "( " << j << ")" << endl;
    }
    }
}

`

For the first loop it was supposed to be {1,1,1} but instead something weird pops up

1( 0) -842150450( 1) -842150450( 2) 2( 0) -842150449( 1) -842150449( 2) 3( 0) -842150448( 1) -842150448( 2)

What can I do so it will work fine?

Aucun commentaire:

Enregistrer un commentaire