Sum of Matrix

QUESTION

Write a C program to find the sum of two matrices of order 2*2 using multidimensional arrays.

“TESTCASE_1”: “2 2\n12 22\n10 12\n2 2\n22 25\n23 9\n###—###SEPERATOR—###—\n34 47 \n33 21”, “TESTCASE_2”: “3 3\n1 2 3\n4 5 6\n7 8 9\n3 3\n1 2 3\n4 5 6\n7 8 9\n###—###SEPERATOR—###—\n2 4 6 \n8 10 12 \n14 16 18”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
 
int main()
{
   int m, n,p,q, c, d, first[10][10], second[10][10], sum[10][10];

   scanf("%d %d", &m, &n);
   
 
   for (c = 0; c < m; c++)
      for (d = 0; d < n; d++)
         scanf("%d", &first[c][d]);
 scanf("%d %d", &p, &q);
   
 
   for (c = 0; c < p; c++)
      for (d = 0 ; d < q; d++)
         scanf("%d", &second[c][d]);
 
   
 
   for (c = 0; c < m; c++) {
      for (d = 0 ; d < n; d++) {
         sum[c][d] = first[c][d] + second[c][d];
         printf("%d ", sum[c][d]);
      }
      printf("\n");
   }
 
   return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro