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 many types of operators are there in c?
How many data structures are there in c?
Explain how can I pad a string to a known length?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
What is main () in c language?
Are pointers integers in c?
Is there any data type in c with variable size?
What is class and object in c?
Explain is it better to bitshift a value than to multiply by 2?
pgm to find any error in linklist(in single linklist check whether any node points any of previous nodes instead of next node)
what will be the output for the following main() { printf("hi" "hello"); }
How main function is called in c?
What is the use of in c?
how do you programme Carrier Sense Multiple Access
differentiate built-in functions and user – defined functions.