-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetrixTranspose.c
More file actions
159 lines (142 loc) · 4.02 KB
/
Copy pathmetrixTranspose.c
File metadata and controls
159 lines (142 loc) · 4.02 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
/**
* @file matrixCalculation.c
* 53. Write a program to perform manipulation of matrix using different module as follows -
Addition () -> to make addition of two matrix
Subtraction () -> to make subtraction of two matrix
Multiplication () -> to multiply two matrices
Transpose () -> to transpose the 1st matrix
Print () -> print any matrix
* @author Md. Alamin (alamin5g@yahoo.com)
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-03-15
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
#include <math.h>
void main()
{
int row, col, n, selection;
printf("Enter your matrix size: \n");
scanf("%d", &n);
int a1[n][n], a2[n][n], add[n][n], sub[n][n], mul[n][n], transpose[n][n], transpose2[n][n];
printf("Enter your 1st matrix value: \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
scanf("%d", &a1[row][col]);
}
}
printf("\nEnter your 2nd matrix value: ");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
scanf("%d", &a2[row][col]);
}
}
printf("\n\n**************************************\n");
printf("\nPress 1 for matrix addition\nPress 2 for matrix subtraction\nPress 3 for matrix multiplication\nPress 4 for transpose of matrix\nPress 5 for print the matrix\n");
scanf("%d", &selection);
switch (selection)
{
case 1:
printf("Addition of 2 matrix : \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
add[row][col] = a1[row][col] + a2[row][col];
printf("%d ", add[row][col]);
}
printf("\n");
}
break;
case 2:
printf("Subtraction of 2 matrix : \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
sub[row][col] = a1[row][col] - a2[row][col];
printf("%d ", sub[row][col]);
}
printf("\n");
}
break;
case 3:
printf("Multiplication of 2 matrix : \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
mul[row][col] = a1[row][col] * a2[row][col];
printf("%d ", sub[row][col]);
}
printf("\n");
}
break;
case 4:
printf("Transpose of 1st matrix : \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
transpose[col][row] = a1[row][col];
}
}
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
printf("%d ", transpose[row][col]);
}
printf("\n");
}
printf("Transpose of 2nd matrix : \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
transpose2[col][row] = a2[row][col];
}
}
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
printf("%d ", transpose2[row][col]);
}
printf("\n");
}
break;
case 5:
printf("1st matrix: \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
a1[row][col];
printf("%d ", a1[row][col]);
}
printf("\n");
}
printf("2nd matrix: \n");
for (row = 1; row <= n; row++)
{
for (col = 1; col <= n; col++)
{
a2[row][col];
printf("%d ", a2[row][col]);
}
printf("\n");
}
break;
default:
printf("invalid!!");
break;
}
}