Заполнить массив А - C#
Формулировка задачи:
Заполнить целочисленный массив А, не вводя значения его элементов с клавиатуры, следующим образом:
1 1 1 1 1
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
1 1 1 1 1
Помогите, пожалуйста
Решение задачи: «Заполнить массив А»
textual
Листинг программы
using System;
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
int [,]arr=new int[5,5];
for (int i = 0; i<arr.GetLength(0); i+=2)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
arr[i, j] = 1;
if (i + 1 < arr.GetLength(0))
{
arr[i + 1, j] = j == 2 ? 1 : 0;
}
}
}
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.Write(arr[i,j]+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}