Problem in realizing the sum of the lines of a two-dimensional matrix C++

Asked

Viewed 138 times

-1

include

include

using namespace Std; int main() {

srand(time(0));
int bid[3][3];
int impar = 0;
for (int x = 0; x < 3; x++)  
{
    for (int y = 0; y < 3; y++)
    {
        bid[x][y] = rand() % (386 - 0 + 1) + (-112);
    }
}
for (int a = 0; a < 3; a++)  
{
    for (int b = 0; b < 3; b++)
    {
        cout << bid[a][b] << "  ";
    }
    cout << endl;
}
// PARTE DA SOMA DAS LINHAS 

int vetor[3];
for (int j = 0; j < 3; j++)
{
        vetor[0] += bid[j][0];
}

for (int j = 0; j < 3; j++)
{
    vetor[1] += bid[j][1];
}

for (int j = 0; j < 3; j++)
{
    vetor[2] += bid[j][2];
}

for (int i = 0; i < 3; i++)
{
    cout << "A soma das colunas eh: " << vetor[i];
}


system("pause");

}

The code works until the part of creating a one-dimensional matrix to receive the sum of the lines, and generates the errors C2146 and C2065, I have tried everything to compile and unsuccessfully

2 answers

0

Though you say so

The code works until the part of creating a one-dimensional matrix for

actually your code nay worked, since compilation errors occurred.

I copied the code you posted and opened it on the way in, look what came up:

// PARTE DA SOMA DAS LINHAS 

int vetor[3];
for (int j = 0; j < 3; j++)
{
    vetor[0] += bid[j][0]<feff>;
}

for (int j = 0; j < 3; j++)
{
    vetor[1] += bid[j][1]<feff>;
}

for (int j = 0; j < 3; j++)
{
    vetor[2] += bid[j][2]<feff>;
}

In other words, there is trash at the end of this line with "Feff". You probably pasted parts of another source that was in UTF-8.

Solution is simple: rewrite the end of these lines.

  • Excuse my ignorance, I am new in the middle and I could not understand your answer, could explain to me what would be UTF-8 and which part I would need to rewrite ?

  • delete the lines where I marked Feff, and rewrite them, this will probably solve the problem

0

To add the columns use the same structure you used for reading:

for (int i = 0; i < 3; i++) {
    vetor[i] = 0;
    for (int j = 0; j < 3; j++) {
            vetor[i] += bid[j][i];
    }
    cout << "A soma da coluna: " << i << " eh: " << vetor[i];
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.