+ 1
Program that prints upper triangle matrix
1 2 3 4 5 6 7 8 9
2 odpowiedzi
+ 8
If I am not wrong, you are looking for -
1 0 0
4 5 0
7 8 9
Try following -
int i, j, k=1;
for(i=0; i<3; i++) {
for(j=0; j<3; j++) {
if(j<=i)
cout << k + " ";
else
cout << "0 ";
k++;
}
cout << endl;
}
0
If I am understanding your question correctly.. then you want to print
1 2 3 4
0 5 6 7
0 0 8 9
0 0 0 1
for matrix
1 2 3 4
4 5 6 7
7 1 8 9
9 6 7 1
All the elements below major diagonal of U are zero.
U[i,j] = 0, If i > j.
U[i,j] = A[i,j], If i <= j.
http://www.techcrashcourse.com/2015/03/c-program-upper-triangular-matrix.html
Similarly, we also have lower triangular matrix
http://www.techcrashcourse.com/2015/03/c-program-lower-triangular-matrix.html