From 343ecaa3e8f07e6411b42b06c9b4dc90f881d305 Mon Sep 17 00:00:00 2001 From: areenoverclouds Date: Tue, 25 May 2021 17:55:09 +0530 Subject: [PATCH] Added sum of rows of 2D array --- SumofRows.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 SumofRows.cpp diff --git a/SumofRows.cpp b/SumofRows.cpp new file mode 100644 index 0000000..4c4d1ca --- /dev/null +++ b/SumofRows.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +int main() +{ + int i,j, m, n; + cout<<"\nEnter number of rows and coloumns : "; + cin>>m>>n; + int arr[m][n]; + cout<<"\nEnter elements of matrix : \n"; + for (i = 0; i < m; i++) + for (j = 0; j < n; j++) + cin>>arr[i][j]; + + cout << "\nFinding Sum of each row:"; + int sum=0; + + for (i = 0; i < m; ++i) {s + for (j = 0; j < n; ++j) { + sum = sum + arr[i][j]; + } + cout<< "\nSum of the row "<< i << " = " << sum << endl; + sum = 0; + } + + return 0; +} \ No newline at end of file