-
Notifications
You must be signed in to change notification settings - Fork 10
/
matrices1.c
109 lines (99 loc) · 1.48 KB
/
matrices1.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
Name:Shreya Nigudkar
U.no.: UIT2023846
TO ADD,SUBTRACT,MULTIPLY 2 MATRICES
*/
#include <stdio.h>
int main(void){
int i=0;
int j=0;
int m=0;
int n=0;
int a[3][3]={0};
int b[3][3]={0};
int c[3][3]={0};
int d[3][3]={0};
int e[3][3]={0};
printf("Enter elements of first matrix:\n");
for (i=0;i<3;i++){
for (j=0;j<3;j++){
scanf("%d",&a[i][j]);
}
}
printf("\n");
printf("Enter elements of second matrix:\n");
for (m=0;m<3;m++){
for (n=0;n<3;n++){
scanf("%d",&b[m][n]);
}
}
printf("\n");
printf("\nFirst matrix:\n");
for (i=0;i<3;i++){
for (j=0;j<3;j++){
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("\nSecond matrix:\n");
for (m=0;m<3;m++){
for (n=0;n<3;n++){
printf("%d ",b[m][n]);
}
printf("\n");
}
int ch;
do {
printf("\nEnter\n \t1 for addition\n\t2 for subtraction\n\t3 for multiplication\n\t4 to exit");
printf("\nEnter choice:");
scanf("%d",&ch);
switch (ch)
{
//addition
case 1:
printf("Addition is:\n");
for (i=0;i<3;i++){
for (j=0;j<3;j++){
c[i][j]=a[i][j]+b[i][j];
printf("%d ",c[i][j]);
}
printf("\n");
}
printf("\n");
break;
//Subtraction
case 2:
printf("Subtraction is:\n");
for (i=0;i<3;i++){
for (j=0;j<3;j++){
d[i][j]=a[i][j]-b[i][j];
printf("%d ",d[i][j]);
}
printf("\n");
}
printf("\n");
break;
//multiplication
case 3:
printf("Multiplication is:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(int k=0;k<3;k++)
{
e[i][j]=e[i][j]+(a[i][k]*b[k][j]);
}
printf("%d ",e[i][j]);
}
printf("\n");
}
break;
default:
printf("Exit!!!");
break;
} //switch ends
} //do ends
while(ch!=4);
return 0;
}