I'm looking for a C++ way using vector to get all the diagonals of a (square) matrix, represented as a 2d vector.
matrix = [
[1,2,3,4],
[5,1,2,3],
[9,5,1,2]]
But I have trouble coming up with a way to generate all the diagonals. The output I'm looking for is:
"[9]", "[5, 5]", "[1, 1, 1]", "[2, 2, 2]", "[3, 3]", "[4]".
What I have tried:
I tried but I can only print the elements of the main diagonal. Could someone show how to print all the diagonal elements.