-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution of the Matrix
105 lines (86 loc) · 2.04 KB
/
Solution of the Matrix
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
#include<stdio.h>
int main()
{
//Part i.
int i, j, n;
printf("Enter an integer number: ");
scanf("%d",&n);
printf("The dimension of array is = %d:%d\n\n",n,n);
int A[n][n];
//Taking input the array values
for(i=0; i<n; i++) {
for(j=0;j<n;j++) {
printf("Enter the value for arr[%d][%d]:", i, j);
scanf("%d", &A[i][j]);
}
printf("\n");
}
//Printing array elements
printf("%d:%d Dimensional array elements:\n\n",n,n);
for(i=0; i<n; i++) {
for(j=0;j<n;j++) {
printf("\t%d",A[i][j]);
}
printf("\n\n");
}
//Part ii.
int B[n][n];
//Store the value of A in B
for(i=0; i<n; i++) {
for(j=0;j<n;j++) {
B[i][j]=A[i][j];
}
}
//Store the value of B in temp & interchange
for (i = 0; i < n; i++){
int temp = B[i][i];
B[i][i] = B[i][n - i - 1];
B[i][n - i - 1] = temp;
}
//Printing Interchange diagonal value
printf("Interchange diagonals of the matrix A:\n\n");
for (i = 0; i < n; i++){
for (j = 0; j < n; j++){
printf("\t%d",B[i][j]);
}
printf("\n\n");
}
//Part iii.
int C[n][n];
// computing the transpose
for (i=0; i<n; i++)
for (j=0; j<n; j++){
C[j][i] = B[i][j];
}
// printing the transpose
printf("Transpose of the matrix B:\n\n");
for (i=0; i<n; i++){
for (j=0; j<n; j++){
printf("\t%d",C[i][j]);
if (j == n -1 )
printf("\n\n");
}
}
//Part iv.
int D[n][n];
//Calculation of the operation 3A+2B-C
for(i=0; i<n; i++) {
for(j=0;j<n;j++) {
D[i][j] = 3*A[i][j] + 2*B[i][j] - C[i][j];
}
}
printf("The following operation 3A+2B-C:\n\n");
for(i=0; i<n; i++) {
for(j=0;j<n;j++) {
printf("\t%d",D[i][j]);
}
printf("\n\n");
}
return 0;
}
/*
Prepared By:
Mahmudur Rahman Tushar
United International University
Dept. Of CSE
*/