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
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
Find MAXIMUM of three distinct integers using a single C statement
a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if
write a proram to reverse the string using switch case?
What are the application of void data type in c?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
What is switch in c?
What is c language & why it is used?
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
How can I invoke another program (a standalone executable, or an operating system command) from within a c program?
Explain pointer. What are function pointers in C?
Is c compiled or interpreted?
What Is The Difference Between Null And Void Pointer?
What is the role of && operator in a program code?
What is %lu in c?