Not Yet Answered # triangles of matrix

Ancient Dragon 5,243 Discussion Starter sunveer Discussion Starter sunveer n1337 29 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

>>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?)

0

>>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.

0

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

0

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..

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...