RSS

PROGRAM TO PRINT THE SUM OF ALL ROWS AND COLUMNS OF A MATRIX

21 Nov

// THIS PROGRAM PRINTS THE ROW SUM AND COLUMN SUM OF A MATRIX

#include <iostream>

using namespace std;

int main()
{
int row, col;
int arr[100][100];

cout<<“\nEnter the number of rows in the matrix \n”;
cin>>row;
cout<<“\nEnter the number of columns in the matrix \n”;
cin>>col;
cout<<“\nInput the matrix \n”;

for(int i =0; i<row; i++)
for(int j =0; j<col; j++)
cin>>arr[i][j];

int rowsum = 0, colsum = 0;

for(int i =0; i<row; i++)
{
for(int j = 0; j<col; j++)
{
rowsum += arr[i][j];
}
cout<<“\nSum of row “<<i+1<<” is “<<rowsum;
rowsum = 0;
cout<<‘\n’;
}

colsum = 0;
cout<<“\n\n”;

for(int j = 0; j<col; j++)
{
for(int i =0; i<row; i++)
{
colsum += arr[i][j];
}
cout<<“\nSum of column “<<j+1<<” is “<<colsum;
colsum = 0;
cout<<‘\n’;
}
return 0;
}

Advertisements
 
Leave a comment

Posted by on November 21, 2015 in Matrices

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: