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
What's a good way to check for "close enough" floating-point equality?
How to explain the final year project as a fresher please answer with sample project
Does free set pointer to null?
What are keywords in c with examples?
Which one would you prefer - a macro or a function?
What is pointers in c with example?
How can I find out how much free space is available on disk?
Create a simple code fragment that will swap the values of two variables num1 and num2.
What does c mean?
How can I sort more data than will fit in memory?
the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What is character constants?
Explain how do you list a file’s date and time?
Write a code to generate divisors of an integer?