Copy of Vectors

0

Good evening! I'm having a question about how to copy a vector.

I declare a vector "matrix [a] [j]" and I need to take the arithmetic mean only of the values contained in "array [a]", so I need to make a copy only of the values "[a]" for an auxiliary vector , and I can not. I created a function that makes the copy of the matrix to another, but this one giving error because the main vector is different from the auxiliary one.

Here is the code for the copy function:

void copiaMatriz (int matriz[], int vetorAux[]){

int count;
for(count = 0; count < LINHA; count++)
    vetorAux[count] = matriz[count]; }

How do I declare the parent array so that it copies only the elements contained in "[a]"?

Thank you.

    
asked by anonymous 13.04.2016 / 23:49

1 answer

0

Hello, I believe you want to make the arithmetic mean of a line of your array using an auxiliary vector, so you should declare the original array with the two dimensions [i][j] .

void copiaMatriz (int matriz[][colunas], int vetorAux[]){ /* pode-se usar um #define para as "colunas"*/

/* linha = linha da matriz em que se deseja copiar */

int i;
for(i = 0; i < linha; i++){
vetorAux[i] = matriz[linha][i];

or, if you prefer, you can do the average directly:

float media_matriz(int n, float mat[]["n"]) {  /* lembrando que não se deve utilizar a variavel diretamente na matriz sem antes defini-la, por isso as aspas */
/* n = numero de colunas */
float media;
int i;
    for(i=0;i<n;i++) 
    {
            media = media + mat["linhaDesejada"][i];
    }
    media = media/("Colunas");

return media;
}
    
04.05.2016 / 19:52