From 280017c19e2c999313bfa0c16babe6b652c7a16c Mon Sep 17 00:00:00 2001 From: Bhawna Khatri Date: Wed, 26 May 2021 01:58:09 +0530 Subject: [PATCH] Row wise sum in 2D array --- RowWiseSum_2DArray.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 RowWiseSum_2DArray.cpp diff --git a/RowWiseSum_2DArray.cpp b/RowWiseSum_2DArray.cpp new file mode 100644 index 0000000..1da32be --- /dev/null +++ b/RowWiseSum_2DArray.cpp @@ -0,0 +1,56 @@ +#include + +using namespace std; + +int main () +{ + +int x,y; + +cout << "Enter no. of row - "; cin >> x; + +cout << "Enter no. of columns - "; cin >> y; + + + +int arr[x][y]; + + +cout << "Enter elements - " << endl; + + +for (int i = 0; i < x; i++) { +for (int j = 0; j < y; j++) { + +cin >> arr[i][j]; + +} +cout << "\n"; + +} + + + +cout << "\n - Sum of each row - \n\n"; + + +for (int i = 0; i < x; ++i) { + +int sum = 0; + +for (int j = 0; j < y; ++j) { + + +sum = sum + arr[i][j]; // sum of rows + + } + +cout << "Sum of row " << i << " = " << sum << endl; + + +} + + +return 0; + +}