## nickymarden 3 years ago Can someone tell me what's wrong with this?

1. nickymarden

#include <stdio.h> #include <stdlib.h> void lerMatriz(int *mat, int m, int n) { // incremento do endereco contido na variavel auxiliar int i, j; for (i = 0; i < m; i = i + 1) for (j = 0; j < n; j = j + 1) scanf("%d", &mat[i * n + j]); } void somarMatrizes(int *a, int *b, int *c, int m, int n) { int i, j, k; for (i = 0; i < m; i = i + 1) { k = i * n; for (j = 0; j < n; j = j + 1) c[k + j] = a[k + j] + b[k + j]; } } void escreverMatriz(int *mat, int m, int n) { // base (mat) mais deslocamento (i * m + j) int i, j, k; for (i = 0; i < m; i = i + 1) { k = i * n; for (j = 0; j < n; j = j + 1) printf("%3d", mat[k + j]); printf("\n"); } } int main(void) { int m, n, *m1, *m2, *m3; scanf("%d", &m); scanf("%d", &n); m1 = (int *)malloc(sizeof(int) * m * n); m2 = (int *)malloc(sizeof(int) * m * n); m3 = (int *)malloc(sizeof(int) * m * n); lerMatriz(m1, m, n); escreverMatriz(m1, m, n); lerMatriz(m2, m, n); escreverMatriz(m2, m, n); printf("\n"); somarMatrizes(m1, m2, m3, m, n); escreverMatriz(m3, m, n); system("RETURN"); }

2. bdean20

Seems to work just fine for me. I don't know what the system("RETURN") is doing there, though. This is the exact code I was using: http://pastebin.com/FaW39mdS

3. nickymarden

thaank you. :))