printing only shaded element on a matrix

Hi,
this is a matrix
35 1 6 26
3 32 7 21
31 9 2 22
8 28 33 17

how can I print and display just these numbers by using 2-dimention number :
35 1 6
3 32
31

please could anyone tell me

I write that code but it doesn`t working,I even don`t understand how to write it hehehe

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream.h>

int main()
{

	
int x[4][4]={{35 ,1, 6 ,26},{3, 32, 7, 21},{31, 9 ,2 ,22},{8, 28, 33 ,17}};

for(int i=0;i<4;i++)
{
for(int k=0;k<i;k++)
for(int j=0;j<4;j++)

	if((i+j)<(4-1))
	
	cout<<" "<<x[i][j];
	
	cout<<endl;		
	
}
		

	


}
	
Last edited on
is there someone can help me
Only two nested loops.

The outer loop looks one row at a time. You apparently don't have to look at all rows of the matrix.

The inner loop prints elements from the current row. Compute the needed columns from the row-number.

I'll give a hint:
1
2
3
4
5
6
for ( size_t row = 0; row < Rows; ++row ) {
  for ( size_t col = 0; col < (Cols - row); ++col ) {
    std::cout << ' ' << col;
  }
  std::cout << '\n';
}
Topic archived. No new replies allowed.