Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

nickymarden

  • 3 years ago

I've already asked in the ComputerScience section but no one answered. Can someone please tell mw 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. A.Avinash_Goutham
    • 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; // printf("entered loop\n"); for (i = 0; i < m; i ++) { for (j = 0; j < n; j = j + 1) { printf("enter mat[%d][%d]:",i,j); scanf("%d", &mat[i * n + j]); } } // printf("exit loop"); return; } void somarMatrizes(int *a, int *b, int *c, int m, int n) { int i, j, k; for (i = 0; i < m; i++) { 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; printf("enter m:"); scanf("%d", &m); printf("enter n:"); scanf("%d", &n); m1 = (int *)malloc(sizeof(int) * m * n); //printf("malloc\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"); }

  3. 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