-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23_Row_sum_2D_Array.cpp
More file actions
52 lines (38 loc) · 943 Bytes
/
Copy path23_Row_sum_2D_Array.cpp
File metadata and controls
52 lines (38 loc) · 943 Bytes
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
#include <iostream>
using namespace std;
void rowSum(int matrix[][3], int rows, int cols){
// int sum=0; when we want 1 st sum also.
for (int i = 0; i < 3; i++)
{
int sum=0;
for (int j= 0; j < 3; j++)
{
// sum=sum+matrix[i][j];
sum += matrix[i][j];
}
cout<<sum<<endl;
}
}
int main(){
int arr[3][3];
cout<<"Enter the elements:"<<endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cin>>arr[i][j];
}
}
cout<<"Printing 2D-Array"<<endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<"the row-wise sum of the 2D-Array is:"<<endl;
rowSum(arr,3,3);
return 0;
}