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
Explain what is wrong with this statement? Myname = ?robin?;
Tell me what is the purpose of 'register' keyword in c language?
What are the different properties of variable number of arguments?
Why pointers are used?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
What is dangling pointer in c?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
application attempts to perform an operation?
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
write a c program for swapping two strings using pointer
Write a program to print numbers from 1 to 100 without using loop in c?
What is #include stdio h?
Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is a pointer in c plus plus?
Can static variables be declared in a header file?