Skip to main content

Add Two Matrix.

Program to add two matrix.


CODE

👇

  1. #include<stdio.h>
  2. #include<conio.h>

  3. void main()
  4. {
  5.     int m, n, c, d, first[10][10], second[10][10], sum[10][10];
  6.     
  7. printf("Enter the number of rows and columns of matrix :");
  8.     scanf("%d%d", &m, &n);
  9.     printf("\nEnter the elements of first matrix : \n");

  10.     for (c = 0; c < m; c++)
  11.     {
  12.         for (d = 0; d < n; d++)
  13.         {
  14.             scanf("%d", &first[c][d]);
  15.         }
  16.     }

  17.     printf("\nEnter the elements of second matrix : \n");

  18.     for (c = 0; c < m; c++)
  19.     {
  20.         for (d = 0; d < n; d++)
  21.         {
  22.             scanf("%d", &second[c][d]);
  23.         }
  24.     }

  25.     printf("\nSum of entered matrices : \n");

  26.     for (c = 0; c < m; c++)
  27.     {
  28.         for (d = 0; d < n; d++)
  29.         {
  30.             sum[c][d] = first[c][d] + second[c][d];
  31.             printf("%d\t", sum[c][d]);
  32.         }
  33.         printf("\n");
  34.     }
  35. }

👉Execute👈


//OUTPUT

/*

Enter the number of rows and columns of matrix :2

2


Enter the elements of first matrix : 4

6

11

9


Enter the elements of second matrix : 24

75

15

31


Sum of entered matrices : 

28 81

26 40


*/



                                                                                     //ThE ProFessoR