Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
static void Main(string[] args)
{
Console.WriteLine("Введите n:");
int n = Int32.Parse(Console.ReadLine());
//Строим матрицу
int[,] mx = new int[n,n];
bool invert = true;
for (int i = 0, c = 1; i < n; i++) {
for (int j = 0; j < n; j++,c++) {
int inx = invert ? n - j - 1: j;
mx[inx, i] = c;
}
invert = !invert;
}
//Выводим
int maxWidth = (n * n).ToString().Length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
sb.Append(mx[i, j]).Append(' ', maxWidth - mx[i, j].ToString().Length+1);
sb.AppendLine();
}
Console.WriteLine(sb);
Console.ReadKey();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question