How can i print the lower and upper triangles of matrix
Please guide me in writing the code.
i don't know even how to start writing the code.
Please help.

>>i don't know even how to start writing the code
Start here

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    // put your code here

}

First, you need to declare the matrix. How many dimensions does it have (2, 3, 4, 5, ...) What dimensions does it have? What type (int, short, double, char*, or something else?)

>>i don't know even how to start writing the code
Start here

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    // put your code here

}

First, you need to declare the matrix. How many dimensions does it have (2, 3, 4, 5, ...) What dimensions does it have? What type (int, short, double, char*, or something else?)

i want to know that after accepting values from user what i have to do to print the triangles.

Do you mean you need to print the LU factorization of the matrix?

if so, perhaps this page might be of some assistance...

i want that if matrix is
1234
4567
8901
2345
then i want to print lower triangle
that is
1
45
890
2345
and upper triangle
1234
567
01
5

Oh, well in that case, how are you storing the matrix? Probably an array of numbers, I would guess.

If you are just starting, might be easiest to use a 2D array; declare an mxn array of integers (or whatever data type you need to hold, where m = number of rows, n = number of columns). If you are dealing strictly with square matrices, then m = n.

For the upper triangular one:
Simply loop through and print out the first n entries of row 1, (n-1) entries of row 2, (n-2) entries of row 3, ... , (n - (m-1)) = (n - m + 1) entries of row m.

If you are a little heavier on the math side, you could also try to implement it using a 1D array, (after all, a rectangular 2D array is really just a 1D array in disguise).

Ummm, the lower triangular one is very similar, if you can see the pattern then you should be on track to solving it now..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.