DESCRIPTION-: This program take matrix as input and again generate matrix as output in which sum of each row elements is placed in corrosponding row and also sum of each column elements is placed in corrosponding column and also calculate the total of all elements.
FOR EXAMPLE-:
If we have input matrix as-----
2 3
1 5
Then it generate output as--------
2 3 5
1 5 6
3 8 11
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"enter the row and column of matrix";
cin>>m>>n;
cout<<"enter elements of array"<<"\n";
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][n]+a[i][j];
}
}
for(j=0;j<n;j++)
{
a[m][j]=0;
for(i=0;i<m;i++)
{
a[m][j]=a[m][j]+a[i][j];
}
}
a[m][n]=0;
for(i=0;i<m;i++)
{
a[m][n]=a[m][n]+a[i][n];
}
cout<<"\n";
for(i=0;i<m+1;i++)
{
cout<<"\n";
for(j=0;j<n+1;j++)
{
cout<<a[i][j]<<"\t";
}
}
getch();
}
FOR EXAMPLE-:
If we have input matrix as-----
2 3
1 5
Then it generate output as--------
2 3 5
1 5 6
3 8 11
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"enter the row and column of matrix";
cin>>m>>n;
cout<<"enter elements of array"<<"\n";
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][n]+a[i][j];
}
}
for(j=0;j<n;j++)
{
a[m][j]=0;
for(i=0;i<m;i++)
{
a[m][j]=a[m][j]+a[i][j];
}
}
a[m][n]=0;
for(i=0;i<m;i++)
{
a[m][n]=a[m][n]+a[i][n];
}
cout<<"\n";
for(i=0;i<m+1;i++)
{
cout<<"\n";
for(j=0;j<n+1;j++)
{
cout<<a[i][j]<<"\t";
}
}
getch();
}
0 comments:
Post a Comment