0
I have a vector that only has integers 1 and 2 randomly allocated. Example:
int vetor[15] = {1,1,1,2,2,1,1,2,2,2,1,1,1,2,1};
How the vector would be printed:
1 1 1 2 2 1 1 2 2 2 1 1 1 2 1
I have this same vector in table form (two-dimensional matrix):
int tabela[3][5] = {{1,1,1,2,2},{1,1,2,2,2},{1,1,1,2,1}};
How the table would be printed:
[,0][,1][,2][,3][,4]
[0,] 1 1 1 2 2
[1,] 1 1 2 2 2
[2,] 1 1 1 2 1
Note that there are (in the example) 3 rows and 5 columns, but this may vary.
Would it be possible count the quantity of number 1 every 5 values (in the case of the one-dimensional vector) and store the responses in a one-dimensional vector? That is, each index of the vector is the count response of a line.
Response vector:
int resposta[];
OR count the number 1 quantity on each line (which is the number of columns in the table) and store the responses in a one-dimensional vector (or two-dimensional, providing line and response to the side)?
int respostaTabela[][2];
Anyway the values stored in the response vector would be:
resposta[0] = 3
resposta[1] = 2
resposta[2] = 4
The vector print would be:
3 2 4
The assignment of values to the response table would be the same as (first column to enumerate the row and second column to display the count):
int respostaTabela[][2] = {{1, 3}, {2, 2}, {3, 4}};
And the impression would be:
[0,] 1 3
[1,] 2 2
[2,] 3 4
Thank you for your attention, a hug!