Function to multiply each row of a matrix by the value of its corresponding secondary diagonal

0

I can not get the values of the secondary diagonal of an array by a function.

/*
19) Elabore uma sub-rotina que receba como parâmetro uma matriz A(6,6) e multiplique cada linha pelo
elemento da diagonal principal da linha. A sub-rotina deverá retornar a matriz alterada para ser mos-
trada no programa principal.
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define DIM 6

//Funções
void Prencher_Matriz(int mat[][DIM]);
void Imprimir_Matriz(int mat[][DIM]);

void Armazenar_Diagonal_Secundaria(int mat[][DIM]);
void MultiplicacaoPelaDiagPrincipal(int mat[][DIM]);

int main(int argc, char** argv) {
    int i, j;
    int matriz[DIM][DIM];

    Prencher_Matriz(&matriz);
    Imprimir_Matriz(&matriz);
    Armazenar_Diagonal_Secundaria(&matriz);

    return (EXIT_SUCCESS);
}

void Prencher_Matriz(int mat[][DIM]) {
    int i, j;
    srand(time(NULL));

    for (i = 0; i < DIM; i++) {
        for (j = 0; j < DIM; j++) {
            mat[i][j] = (rand() % 10) + 1;
        }
    }
}

void Imprimir_Matriz(int mat[][DIM]) {
    int i, j;

    printf("MATRIZ GERADA \n");
    for (i = 0; i < DIM; i++) {
        for (j = 0; j < DIM; j++) {
            printf("%4d", mat[i][j]);
        }
        printf("\n");
    }
}

void Armazenar_Diagonal_Secundaria(int mat[][DIM]) {
    int i, j, p = 0;
    int ElementosDS[DIM];

    for (i = 0; i < DIM; i++) {
        for (j = 0; j < DIM; j++) {
            if (i + j == DIM - 1) {
                ElementosDS[p] = mat[DIM - i];
                p++;
            }
        }
    }
}

Well, what I understood what it is to do is store the values of the elements of the main diagonal in a vector and multiply it all of its line by it. Here is an example:

| 1 | 2 | 3 |

| 4 | 5 | 6 |

| 7 | 8 | 9 |

The main diagonal elements of the array above are array is 1, 5 and 9. According to what was requested the generated array would be:

| 1 | 2 | 3 |

| 20 | 25 | 30 |

| 63 | 72 | 81 |

I am not able to pass the array into the functions. I want to do a function to store the elements of the digonal in a vector and then get this same vector generated in that function and throw it in another function to do the calculations on top of the original matrix.     

asked by anonymous 24.07.2018 / 21:08

0 answers