-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.cpp
59 lines (51 loc) · 1.43 KB
/
array.cpp
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
//Table with row and columns. Size depends on user input, user inputs numbers in table
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int rows, cols, totalRows = 0, totalColumns = 0;
int * * arr = nullptr;
cout << endl << "Input Row: ";
cin >> rows;
cout << "Input Column: ";
cin >> cols;
arr = new int*[rows];
cout << endl << endl;
for (int i = 0; i < rows; i++){
arr[i] = new int[cols];
for (int j = 0; j < cols; j++){
cout << "Input number at Row " << i + 1 << " Col " << j + 1 << ": ";
cin >> arr[i][j];
}
}
cout << endl << endl;
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
cout << setw(3) << arr[i][j];
}
cout << endl;
}
cout << endl << endl;
for (int i = 0; i < rows; i++){
for (int j = 0; j < cols; j++){
totalRows += arr[i][j];
}
cout << "The sum of row " << i + 1 << " is " << totalRows << endl;
totalRows = 0;
}
cout << endl << endl;
for (int i = 0; i < cols; i++){
for (int j = 0; j < rows; j++){
totalColumns += arr[j][i];
}
cout << "The sum of column " << i + 1 << " is " << totalColumns << endl;
totalColumns = 0;
}
for (int i = 0; i < rows; i++){
delete [] arr[i];
}
delete [] arr;
cout << endl << endl;
return 0;
}