C++ Online Compiler
Example: Sum of Each Row and Column of a Matrix in C++ language
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Sum of Each Row and Column of a Matrix in C++ language #include <iostream> using namespace std; int main() { int a[10][10], i, j, x, y, sum = 0; cout << "-----Enter the number of rows & columns of the matrix-----\n"; cin >> x >> y; cout << "\n-----Enter the co-efficients of the matrix-----\n"; for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { cin >> a[i][j]; } cout << "\n"; } for (i = 0; i < x; ++i) { for (j = 0; j < y; ++j) { sum = sum + a[i][j] ; } cout << "The Sum of the " << i << " position row is = " << sum << "\n"; sum = 0; } cout << "\n"; sum = 0; for (j = 0; j < y; ++j) { for (i = 0; i < x; ++i) { sum = sum + a[i][j]; } cout << "The Sum of the " << j << " position column is = " << sum << "\n"; sum = 0; } return 0; }
3 4 23 45 23 54 24 34 65 76 34 86 56 87
Output
Clear
ADVERTISEMENTS