Answer the question
In order to leave comments, you need to log in
How to print the diagonals of a matrix not from left to right?
I solve the problem of finding sequences of identical balls on the diagonals.
There is a code for displaying / passing along the diagonals of the matrix from left to right, from top to bottom.
int size = 9; //Размер матрицы 9x9
string diagonal = "";
for (int k = 0; k < size * 2; k++)
{
for (int j = 0; j <= k; j++)
{
int i = k - j;
if (i < size && j < size)
{
diagonal += mat[j, i] + " ";
}
}
print(diagonal);
diagonal = "";
}
Answer the question
In order to leave comments, you need to log in
My decision:
for (int k = size; k >= -size; k--)
{
for (int j = 0; j < size - k; j++)
{
int i = k + j;
if (i < size && j < size && i >= 0 && j >= 0)
{
diagonal += arr2[j, i] + " ";
}
}
Console.WriteLine(diagonal);
diagonal = "";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question