-
Notifications
You must be signed in to change notification settings - Fork 1
/
addMatrix.c
43 lines (43 loc) · 1.04 KB
/
addMatrix.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
//
// Created by sids on 30/10/18.
//
#include <stdio.h>
int matrix(int i, int j);
int main(){
int i,j,k;
printf("Enter the rows in the first 2D array.\n");
scanf("%d",&i);
printf("Enter the columns in the first and rows in the second 2D array.\n");
scanf("%d",&j);
matrix(i,j);
return 0;
}
int matrix(int i,int j){
int first[i][j],second[i][j],added[i][j],m,n;
printf("Please enter the elements in the first matrix.\n");
for(m=0;m<i;m++){
for(n=0;n<j;n++){
scanf("%d",&first[m][n]);
second[m][n]=first[m][n];
}
}
printf("Please enter the elements in the second matrix.\n");
for(m=0;m<i;m++){
for(n=0;n<j;n++){
scanf("%d",&second[m][n]);
}
}
for(m=0;m<i;m++){
for(n=0;n<j;n++){
added[m][n]=first[m][n]+second[m][n];
}
}
printf("The resultant added matrix is: \n");
for(m=0;m<i;m++){
for(n=0;n<j;n++){
printf("%d ",added[m][n]);
}
printf("\n");
}
return 0;
}