Program that prints upper triangle matrix | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Program that prints upper triangle matrix

1 2 3 4 5 6 7 8 9

18th Feb 2017, 7:29 PM
Samiyah
2 Answers
+ 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; }
18th Feb 2017, 8:12 PM
Manthan Raja
Manthan Raja - avatar
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
15th Apr 2017, 1:44 PM
Arun Kumar
Arun Kumar - avatar