-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathentire_array.cpp
More file actions
executable file
·165 lines (116 loc) · 2.59 KB
/
Copy pathentire_array.cpp
File metadata and controls
executable file
·165 lines (116 loc) · 2.59 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
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int choice;
cout << "select any one\n1. Sum of 2 matrices.\n2. Sum of row and columns.\n";
cout << "Choice: ";
cin >> choice;
if(choice == 1)
//SUM OF 2 MATRICES
{
int A[10][10], B[10][10], C[10][10], r1, r2, c1, c2, i, j, p, q, r, s;
cout << "Enter the number of rows and columns of Matrice 1: ";
cin >> r1 >> c1;
cout << "Enter the number of rows and columns of Matrice 2: ";
cin >> r2 >> c2;
if (((r1 == r2) && (c1 == c2)))
{
cout << "Addition possible\n";
}
else
{
cout << "Addition isn't possible\n";
exit(0);
}
cout << "Enter elements for matrice 1: \n";
//Taking matrice 1 from user
for(i = 0; i < r1; i++)
{
for(j = 0; j < c1; j++)
{
cout << "Enter value for " << i << ", " << j << ": ";
cin >> A[i][j];
}
}
cout << "Enter the elements of matrice 2: \n";
//Taking matrice 2 from user
for(p = 0; p < r2; p++)
{
for(q = 0; q < c2; q++)
{
cout << "Enter value for " << p << ", " << q << ": ";
cin >> B[p][q];
}
}
//adding them together
for(r = 0; r < r1; r++)
{
for(s = 0; s < c1; s++)
{
C[r][s] = A[i][j] + B[p][q];
}
}
//displaying output
cout << "sum of 2 matrices is: ";
for(r = 0; r < r1; i++)
{
cout << "\n";
for(s = 0; s < c1; s++)
{
cout << C[r][s];
}
}
}
if(choice == 2)
{
int A[10][10], i, j, r[10], c[10], row, col;
cout << "Enter the number of rows: ";
cin >> row;
cout << "Enter the number of columns: ";
cin >> col;
for(i = 0; i < row; i++)
{
for(j = 0; j < col; j++)
{
cout << "Enter the element " << i << ", " << j << ": ";
cin >> A[i][j];
}
}
cout << "Given matrix is: ";
for(i = 0; i < row; i++)
{
cout << "\n";
for(j = 0; j < col; j++)
{
cout << A[i][j] << " ";
}
}
for(i = 0; i < row; i++)
{
r[i] = 0;
for(j = 0; j < col; ++j)
{
r[i] += A[i][j];
}
}
for(j = 0; j < col; ++j)
{
c[j] = 0;
for(i = 0; i < row; i++)
{
c[j] += A[i][j];
}
}
for(i = 0; i < row; ++i)
{
cout << "\nSum of row #" << i + 1 << " is: " << r[i];
}
for(i = 0; i < col; ++i)
{
cout << "\nSum of column #" << i + 1 << " is: " << c[i];
}
} cout << "\n";
return 0;
}