-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 2A (Without Using Pointer)
More file actions
196 lines (185 loc) · 3.19 KB
/
Copy pathAssignment 2A (Without Using Pointer)
File metadata and controls
196 lines (185 loc) · 3.19 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
ASSIGNMENT NO.2 (PART A-Without using pointer)
Title:Represent matrix using two dimensional arrays and perform following operations with and without pointers:
i. Addition
ii. multiplication
iii. transpose
iv. Saddle point
#include<stdio.h>
void addmat(int a[10][10],int b[10][10],int r1,int r2,int c1,int c2);
void mul(int a[10][10],int b[10][10],int r1,int r2,int c1,int c2);
void transpose(int a[10][10],int r1,int c1);
voidsaddlep(int a[10][10],int r1,int c1);
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,r1,r2,c1,c2,ch;
printf("\n Enter the no.s of rows and columns of 1st matrix=");
scanf("%d %d",&r1,&c1);
printf("\n Enter the no.s of rows and columns of 2nd matrix=");
scanf("%d %d",&r2,&c2);
printf("\n Enter the elements of 1st matrix=");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d", &a[i][j]);
}
}
printf("\n Enter the elements of 2nd matrix=");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d", &b[i][j]);
}
}
printf("\n Matrix A=\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
printf("\n Matrix B=\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ", b[i][j]);
}
printf("\n");
}
do
{
printf("\n1.Addition\n2.Multiplication\n3.Transpose\n4.Saddle point");
printf("\n Enter your choice=");
scanf("%d",&ch);
switch(ch)
{
case 1:addmat(a,b,r1,r2,c1,c2);
break;
case 2:mul(a,b,r1,r2,c1,c2);
break;
case 3:transpose(a,r1,c1);
break;
case 4:saddlep(a,r1,c1);
break;
default:printf("\n Invalid choice");
}
printf("Do you want to continue?");
}while(ch!=0);
}
void addmat(int a[10][10],int b[10][10],int r1,int r2,int c1,int c2)
{
inti,j,c[10][10];
if(r1==r2 && c1==c2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
printf("\n sum of matrix=\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
}
else
{
printf("\n Size of both matrix is not matching");
}
}
void mul(int a[10][10],int b[10][10],int r1,int r2,int c1,int c2)
{
inti,j,k,c[10][10];
if(c1==r2)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=0;
}
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n multiplication of matrix=\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
}
void transpose(int a[10][10],int r1,int c1)
{
int i=0,j=0,b[10][10];
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
b[i][j]=a[j][i];
}
}
printf("\n Transpose of matrix=\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
}
voidsaddlep(int a[10][10],int r1,int c1)
{
inti,j,k,min,max,col;
for(i=0;i<r1;i++)
{
min=a[i][0];
for(j=0;j<c1;j++)
{
if(a[i][j]<=min)
{
min=a[i][j];
col=j;
}
}
}
max=a[0][col];
for(k=0;k<r1;k++)
{
if(a[k][col]>=max)
{
max=a[k][col];
}
}
if(min==max)
{
printf("\nsaddle point is (%d, %d)",i,col+1);
printf("\nsaddle point is =%d",max);
}
else
{
printf("No saddle point");
}
}