You are on page 1of 3

C++ program to determine row sum and

column sum of a matrix


Aim:-

To determine row sum and column sum of a matrix

Description:-

For loop-A for loop is a repetition control structure that allows you to efficiently
write a loop that needs to execute a specific number of times.

Syntax
The syntax of a for loop in C++ is −
for ( init; condition; increment ) {
statement(s);
}

Example:-

To determine the row sum and coloumn sum of a 3*3 matrix


1 2 3
(4 5 6)
7 8 9
The sum of row 1 is 6

The sum of row 2 is 15

The sum of row 3 is 24

The sum of column 1 is 12

The sum of column 2 is 15

The sum of column 3 is 18


C++ program
After compiling the program, we should provide the number of rows and
columns of a given matrix

After providing the matrix value, the elements of the matrix should be
provided as shown below

The elements in the matrix are divided in row wise and column wise and
added i.e., the sum of row no 1 is calculated by adding all the elements
in row no 1 and similarly for row no2 and row no3.
For the sum of column no 1 is calculated by adding all the elements in
column no 1 and vice versa.

You might also like