PROGRAM TO FIND ROW SUM, COLUMN SUM AND GRAND TOTAL

/*PROGRAM TO FIND ROW SUM, COLUMN SUM AND GRAND TOTAL*/

#include<conio.h>

#include<iostream.h>

class matrix

{

int a[5][5],i,j,m,n,r_sum,c_sum,col,total;

public:

void input();

void output(int a[][5],int,int);

};

void matrix::input()

{

cout<<“Enter the order of the matrix: “;

cin>>m>>n;

cout<<“Enter “<<m*n<<” elements in the matrix:\n”;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

cin>>a[i][j];

}

output(a,m,n);

};

void matrix::output(int a[][5],int m,int n)

{

cout<<“Elements of given matrix are:\n”;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

cout<<a[i][j]<<”   “;

cout<<endl;

}

col=0;

total=0;

for(i=0;i<m;i++)

{

r_sum=0;

for(j=0;j<n;j++)

{

r_sum=r_sum+a[i][j];

}

cout<<“Sum of elements of “<<i+1<<” row is: “<<r_sum<<endl;

total=total+r_sum;

}

while(col<n)

{

c_sum=0;

for(i=0;i<m;i++)

c_sum=c_sum+a[i][col];

cout<<“Sum of elements of “<<col+1<<” column is: “<<c_sum<<endl;

col++;

total=total+c_sum;

}

cout<<“Grand total is:”<<total;

}

void main()

{

matrix m1;

clrscr();

m1.input();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *