Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define NUM_ROWS 2
- #define NUM_COLUMNS 2
- struct params
- {
- int m_1[NUM_ROWS][NUM_COLUMNS];
- int m_2[NUM_ROWS][NUM_COLUMNS];
- int m[NUM_ROWS][NUM_COLUMNS];
- int row;
- int column;
- };
- typedef struct params params_t;
- void calculate_cell(void *params);
- int main(int argc,char* argv[]){
- int mat1[NUM_ROWS][NUM_COLUMNS] = {{2,2},{5,1}};
- int mat2[NUM_ROWS][NUM_COLUMNS] = {{3,3},{3,4}};
- int matResul[NUM_ROWS][NUM_COLUMNS];
- int i, j, k, result=0;
- params_t *p = malloc(sizeof(params_t));
- // ERRO NO PARSE
- // matriz.c:31:10: error: incompatible types when assigning to type ‘int[2][2]’ from type ‘int (*)[2]’
- p->m_1 = mat1;
- p->m_2 = mat2;
- p->m = matResul;
- for (i = 0; i < NUM_ROWS; i++){
- for (j = 0; j < NUM_COLUMNS; j++) {
- p->row = i;
- p->column = j;
- calculate_cell((void*)p);
- }
- }
- printf("Result\n");
- for(i = 0; i < NUM_ROWS; i++) {
- for (j = 0; j < NUM_COLUMNS; j++)
- printf("%d\t", matResul[i][j]);
- printf("\n");
- }
- return 0;
- }
- void calculate_cell(void *params)
- {
- int i;
- int result = 0;
- int value_row;
- int value_column;
- params_t *p = (params_t *) params;
- for (i = 0; i < 2; i++)
- {
- value_row = p->row;
- value_column = p->column;
- result += p->m_1[value_row][i] * p->m_2[i][value_column];
- }
- p->m[value_row][value_column] = result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement