program to print upper & lower triangle of a matrix
Answer Posted / medhane
#include (iostream.h)
#include (conio.h)
# define n 10
void main( )
{
int mat[n][n];
int d;
// Input elements
cout<< "\n Enter dimension of square matrix:";
cin >> d;
for(int i = 0; i < d ; i++)
for( int j = 0; j < d ; j++)
{cout<<"\n Enter elements for "<< i+1 << "," << j+1
<"location :";
cin >> mat[i][j];
}
clrscr();
//Print the array
cout<<"\n The Original matrix : \n\n";
for( i = 0; i < d ; i++)
{for( j = 0; j < d ; j++)
cout<< mat[i][j]<<"\t";
cout<< "\n";
}
//upper half of left diagonal ----
cout<<"\n The Upper half of the matrix : \n\n";
for( i = 0; i < d ; i++)
{
for( j = 0; j < d ; j++)
{ if(i < j)
cout << mat [i][j] << " " ;
else
cout << " " << " ";
}
cout << "\n ";
}
//lower half of left diagonal -----
cout<<"\n The Lower half of the matrix : \n\n";
for( i = 0; i < d ; i++)
{
for( j = 0; j < d ; j++)
{ if(i > j)
cout << mat [i][j] << " " ;
else
cout << " " << " ";
}
cout << "\n ";
}
getch ( );
}
| Is This Answer Correct ? | 16 Yes | 14 No |
Post New Answer View All Answers
how we can make 3d venturing graphics on outer interface
Explain what are the __date__ and __time__ preprocessor commands?
Is exit(status) truly equivalent to returning the same status from main?
Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.
What are the features of c language?
Is flag a keyword in c?
Can I initialize unions?
Differentiate between the = symbol and == symbol?
What is the use of bitwise operator?
Explain what header files do I need in order to define the standard library functions I use?
What is the meaning of typedef struct in c?
Explain which function in c can be used to append a string to another string?
What is main () in c language?
What is printf () in c?
What is void c?