-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_53.c
More file actions
51 lines (48 loc) · 1.28 KB
/
Copy pathProgram_53.c
File metadata and controls
51 lines (48 loc) · 1.28 KB
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
47
48
49
50
51
// Program 53: Write a program to perform addition of two 2×2 matrices.
#include<stdio.h>
int main(){
int matrix1[2][2];
int matrix2[2][2];
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
printf("Enter the element of matrix 1 at matrix[%d][%d] : ",i,j);
scanf("%d",&matrix1[i][j]);
}
}
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
printf("Enter the element of matrix 2 at matrix[%d][%d] : ",i,j);
scanf("%d",&matrix2[i][j]);
}
}
printf("Matrix - 1 \n");
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
printf("%d",matrix1[i][j]);
}
printf("\n");
}
printf("Matrix - 2 \n");
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
printf("%d",matrix2[i][j]);
}
printf("\n");
}
// row , col ==> input
//condition row1 ==row2 && col1==col2
int matrix_sum[2][2];
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
matrix_sum[i][j] = matrix1[i][j] + matrix2[i][j];
}
}
printf("matrix formed after sum :\n");
for(int i = 0;i<2;i++){
for(int j =0 ;j<2;j++){
printf("%d",matrix_sum[i][j]);
}
printf("\n");
}
return 0;
}