Hello, I'm having a problem adding up each of the rows in my array and storing it in a vector
My code is like this:
#include <stdio.h>
int conta(int * matriz[5][3], int * vet)
{
for (int i = 0 ; i<5; i++)
{
for (int j = 0; j<3;j++)
{
matriz [i][j] = i+j;
vet[i] += matriz[i][j];
}
}
}
void imprimir(int * matriz[5][3], int * vet)
{
for (int i = 0 ; i<5; i++)
{
for (int j = 0; j<3;j++)
{
printf("%d",matriz [i][j]);
}
printf("\n");
}
for (int i = 0; i < 5; ++i)
{
printf("soma linha %d : %d \n", i , vet[i] );
}
}
void main()
{
int matriz [5][3];
int vet[5] = {0};
conta(matriz,vet);
imprimir(matriz,vet);
}
For some reason it returns:
soma linha 0 : 6
soma linha 1 : 27
soma linha 2 : 48
soma linha 3 : 69
soma linha 4 : 90
and not:
soma linha 0 : 3
soma linha 1 : 6
soma linha 2 : 9
soma linha 3 : 12
soma linha 4 : 15
That should be your answer.
Can anyone help me?