Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Code to Print Lower half and Upper half of Triangle Matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// C++ Program to Print Lowerhalf and Upperhalf of Triangle Matrix


#include<iostream>

using namespace std;

int main()
{
int a[10][10],i,j,m;
cout<<"Enter size of the Matrix(min:3,max:5):";
cin>>m;
cout<<"\nEnter the Matrix row wise:\n";

for(i=0;i<m;i++)
for(j=0;j<m;++j)
cin>>a[i][j];

cout<<"\n\n";

cout<<"Upperhalf of Triangle Matrix :: \n";

for(i=0;i<m;++i)
{
for(j=0;j<m;++j)
{
if(i<j)
cout<<a[i][j]<<" ";
else
cout<<" ";
}

cout<<"\n";
}

cout<<"\n";

cout<<"Lowerhalf of Triangle Matrix :: \n";

for(i=0;i<m;++i)
{
for(j=0;j<m;++j)
{
if(j<i)
cout<<a[i][j]<<" ";
else
cout<<" ";
}
cout<<"\n";
}

return 0;
}
49 changes: 49 additions & 0 deletions Find Sum of Diagonals elements in a Matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* C++ Program to Find Sum of Diagonals elements in a Matrix */

#include<iostream>

using namespace std;

int main()
{
int a[10][10],d1sum=0,d2sum=0,m,i,j;
cout<<"Enter size of matrix :: ";
cin>>m;
cout<<"\nEnter Elements to Matrix Below :: \n";

for(i=0;i<m;i++)
{
for(j=0;j<m;++j)
{
cout<<"\nEnter a["<<i<<"]["<<j<<"] Element :: ";
cin>>a[i][j];
}

}

cout<<"\nThe given matrix is :: \n\n";
for (i = 0; i < m; ++i)
{
for (j = 0; j < m; ++j)
{
cout<<"\t"<<a[i][j];
}
printf("\n\n");
}



for(i=0;i<m;++i)
for(j=0;j<m;++j)
{
if(i==j)
d1sum+=a[i][j];
if(i+j==(m-1))
d2sum+=a[i][j];
}

cout<<"\nSum of 1st diagonal is :: "<<d1sum;
cout<<"\n\nSum of 2nd diagonal is :: "<<d2sum;

return 0;
}