Enter elements in a 5*5 matrix
5 6 7 8 9
2 3 4 5 6
0 1 2 3 4
9 10 11 12 13
21 22 23 24 25
The upper half of the primary diagonal is
5 6 7 8 9
3 4 5 6
2 3 4
12 13
25
(Changed the input to represent a table, but I changed nothing in your code.)
Maybe you're confused because the of the layout. Add this line: for(j = 0; j < k; ++j) cout << "\t";
and in the output cout<<a[i][j]<<" ";, change the space " " to "\t" (tab).
That changes the output to:
The upper half of the primary diagonal is
5 6 7 8 9
3 4 5 6
2 3 4
12 13
25