2
Hello, I’m having a problem adding up each of the lines of my matrix and storing 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 he 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.
someone could help me?
Welcome to Stackoverflow in English Miguel. I reversed your title issue with "Solved" because it’s not the way the site works. The indication that is given with the green arrow in an answer alone already indicates whether you solved your problem or not.
– Isac