Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#include
using namespace std;
void matrixrow_add(int a[100][100],int n,int m)
{
cout<<"\n ________________________________________________________________________________\n";
cout<<"\n";
cout<<"\n\n\t => THE ROW WISE SUM OF MATRIX : \n";
cout<<"\n";
int sum=0,sum2=0;
for(int i=0;i<n;i++)
{
cout<<"\t\t\t";
for(int j=0;j<m;j++)
{
cout<<a[i][j]<<" ";
sum=sum+a[i][j];
}
cout<<" = "<<sum;
cout<<"\n\n";
sum=0;
}
}
void matrixcol_add(int a[100][100],int n,int m)
{
cout<<"\n\t => THE COLUMN WISE SUM OF MATRIX : \n";
cout<<"\n";
for(int i=0;i<m;i++)
{
cout<<"\t\t\t";
for(int j=0;j<n;j++)
{
cout<<a[j][i]<<" ";
sum=sum+a[j][i];
}
cout<<" = "<<sum;
cout<<"\n\n";
sum=0;
}
}
void matrixdiag1_add(int a[100][100],int n,int m)
{
cout<<"\n ________________________________________________________________________________\n";
cout<<"\n";
int sum=0,sum2=0,flag,flagi;
for(int i=0;i<n;i++)
{
}
if(n==m)
{
if(flag==1)
{
cout<<"\n\t => SUM OF THE MAJOR DIAGONAL OF MATRIX : "<<sum;
}
if(flagi==1)
{
cout<<"\n\t => SUM OF THE MINOR DIAGONAL OF MATRIX : "<<sum2;
}
}
else
{
cout<<"\n\t => !! ERROR !! No. of rows and columns are not same, so sum of diagonal cannot be calculated. \n";
}
cout<<"\n";
}
void matrixlowtri_add(int a[100][100],int n,int m)
{
cout<<"\n ________________________________________________________________________________\n";
cout<<"\n";
for(int i=0;i<n;i++)
{
cout<<"\n\t\t\t";
for(int j=0;j<m;j++)
{
if(i>=j)
{
cout<<a[i][j]<<" ";
sum=sum+a[i][j];
}
if(i<j)
{
cout<<""<<" ";
}
}
cout<<"\n";
}
cout<<"\n\t => SUM OF LOWER TRIANGULAR ELEMENTS OF THE MATRIX IS : "<<sum;
}
void matrixupptri_add(int a[100][100],int n,int m)
{
cout<<"\n\t => THE UPPER TRIANGULAR ELEMENTS OF MATRIX IS SHOWN BELOW : \n";
int sum=0;
for(int i=0;i<n;i++)
{
cout<<"\n\t\t\t";
for(int j=0;j<m;j++)
{
if(i<=j)
{
cout<<a[i][j]<<" ";
sum=sum+a[i][j];
}
if(i>j)
{
cout<<""<<" ";
}
}
cout<<"\n";
}
cout<<"\n\t => SUM OF UPPER TRIANGULAR ELEMENTS OF THE MATRIX IS : "<<sum;
}
void matrixtranspose(int a[100][100],int n,int m)
{
cout<<"\n ________________________________________________________________________________\n";
cout<<"\n";
cout<<"\n\t => TRANSPOSE OF THE MATRIX IS : \n";
cout<<"\n";
for(int i=0;i<m;i++)
{
cout<<"\t\t\t";
for(int j=0;j<n;j++)
{
cout<<a[j][i]<<" ";
}
cout<<"\n\n";
}
}
int main()
{
int a[100][100],i,j,sum=0,n,m,x;
cout<<"\n\t ======================\n";
cout<<" \t MATRIX OPERATIONS\n";
cout<<" \t ======================\n";
cout<<"\n\n\t Enter the number of rows(n) : ";
cin>>n;
cout<<"\n\t Enter the number of columns(m) : ";
cin>>m;
cout<<"\n\n\t Enter the elements of the matrix : ";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
cout<<"\n\t THE MATRIX YOU ENTERED IS : \n";
for(i=0;i<n;i++)
{
cout<<"\n\t\t\t";
for(j=0;j<m;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<"\n\n\t Enter the program you want to run : ";
cout<<"\n\n\t 1. ROW WISE & COLUMN WISE SUM OF A MATRIX \n";
cout<<"\t 2. SUM OF MAJOR & MINOR DIAGONAL OF A MATRIX\n";
cout<<"\t 3. LOWER TRIANGULAR & UPPER TRIANGULAR ELEMENTS OF MATRIX\n";
cout<<"\t 4. TRANSPOSE OF A MATRIX\n";
cin>>x;
switch(x)
{
case 1:
matrixrow_add(a,n,m);
matrixcol_add(a,n,m);
break;
}