-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMatrix_Addition_user-defined_2.c
46 lines (42 loc) · 1.37 KB
/
Matrix_Addition_user-defined_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*This Program is coded by Mr. Sailesh Singh
You can follow and look after the work done by me on following links
Github: https://github.com/Sailesh-Singh
linkedin: https://www.linkedin.com/in/saileshsingh36
Date of creation:6/8/2020
Please use this for learning purpose only.
*/
//Program to find addition of two user defined matrices (multidimensional(2D) array)
#include<stdio.h>
int main()
{
int i,j,row,column;
printf("Enter the number of rows and columns of matrix\n");
scanf("%d%d", &row, &column);
int a[row][column],b[row][column],sum[row][column];
//Declaration of elements of first matrix
printf("Enter %d elements of first matrix \n",row*column);
for(i=0;i<row;i++)
for(j=0;j<column;j++)
scanf("%d",&a[i][j]);
//Declaration of elements of second matrix
printf("Enter %d elements of second matrix\n",row*column);
for(i=0;i<row;i++)
for(j=0;j<column;j++)
scanf("%d",&b[i][j]);
//Logic for adding two matrices
for (i = 0; i < row; i++)
for (j = 0; j < column; j++)
sum[i][j] = a[i][j] + b[i][j];
//Printing the result of Sum of two matrices
printf("\nSum of two matrices: \n");
for (i = 0; i < row; i++)
for (j = 0; j < column; j++)
{
printf("%d\t", sum[i][j]);
if (j == column - 1)
{
printf("\n");
}
}
return 0;
}