forked from riyaaa04/cpp20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path65.cpp
41 lines (35 loc) · 979 Bytes
/
65.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
#include <iostream>
using namespace std;
int main(){
int rows, cols,sum=0;
int currRow = 1;
cout << "How many rows : ";
cin >> rows;
cout << "How many columns : ";
cin >> cols;
int arr[rows][cols]; //creating matrix of size (rows x cols)
cout << "Enter array elements :\n";
for(int i = 0; i < rows ; i++){
for(int j = 0; j < cols; j++){
cin >> arr[i][j];
}
cout << "\n";
}
//displaying matrix
cout << "Matrix:" << endl;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
cout << arr[i][j] << " ";
}
cout << endl;
}
//iterating through array to calculate sum
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
sum += arr[i][j];
}
cout << "Sum of elements of row "<<currRow << " = " << sum << endl;
currRow++;
sum = 0;
}
}