Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

nickymarden

  • 3 years ago

Can someone tell me what's wrong with this?

  • This Question is Closed
  1. nickymarden
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #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
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    thaank you. :))

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy