//Program to find sum of each row and column and total of matrix.
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
int a[10][10],i,j, m, n;
clrscr();
cout<<endl<<" Enter the rows of matrix: ";
cin>>m;
cout<<endl<<"Enter the column of matrix: ";
cin>>n;
cout<<endl<<"Elements of a matrix:";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0; i<m; i++)
{
a[i][n]=0;
for(j=0; j<n; j++)
{
a[i][n]+=a[i][j];
}
}
for(j=0; j<n; j++)
{
a[m][j]=0;
for (i=0; i<m; i++)
{
a[m][j]+=a[i][j];
}
}
a[m][n]=0;
for(i=0; i<m ; i++)
{
a[m][n]+=a[i][n];
}
cout<<endl<<" a matrix is :"<<endl;
for(i=0;i<m+1;i++)
{
cout<<endl;
for(j=0;j<n+1;j++)
{
cout<<setw(5)<<" "<<a[i][j];
}
}
getch();
}
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
void main()
{
int a[10][10],i,j, m, n;
clrscr();
cout<<endl<<" Enter the rows of matrix: ";
cin>>m;
cout<<endl<<"Enter the column of matrix: ";
cin>>n;
cout<<endl<<"Elements of a matrix:";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0; i<m; i++)
{
a[i][n]=0;
for(j=0; j<n; j++)
{
a[i][n]+=a[i][j];
}
}
for(j=0; j<n; j++)
{
a[m][j]=0;
for (i=0; i<m; i++)
{
a[m][j]+=a[i][j];
}
}
a[m][n]=0;
for(i=0; i<m ; i++)
{
a[m][n]+=a[i][n];
}
cout<<endl<<" a matrix is :"<<endl;
for(i=0;i<m+1;i++)
{
cout<<endl;
for(j=0;j<n+1;j++)
{
cout<<setw(5)<<" "<<a[i][j];
}
}
getch();
}