MuffinMonster

Class Task 52#

Feb 27th, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Fill1(int[,] arr)
  11.         {
  12.             int x = arr.GetLength(1) / 2;
  13.             for (int i = 0; i <= arr.GetLength(0) / 2; i++)
  14.             {
  15.                 arr[i, x] = 1;
  16.                 arr[i, arr.GetLength(1) - x - 1] = 1;
  17.                 arr[arr.GetLength(0) - i - 1, x] = 1;
  18.                 arr[arr.GetLength(0)-i-1,arr.GetLength(1)-x-1] = 1;
  19.                 x--;
  20.             }
  21.         }
  22.         static void Fill2(int[,] arr)
  23.         {
  24.             int x = arr.GetLength(1) / 2 -1;
  25.             for (int i = 0; i < arr.GetLength(0) / 2; i++)
  26.             {
  27.                 arr[i, x] = 1;
  28.                 arr[i, arr.GetLength(1) - x - 1] = 1;
  29.                 arr[arr.GetLength(0) - i - 1, x] = 1;
  30.                 arr[arr.GetLength(0) - i - 1, arr.GetLength(1) - x - 1] = 1;
  31.                 x--;
  32.             }
  33.         }
  34.         static void Main(string[] args)
  35.         {
  36.             int a = int.Parse(Console.ReadLine());
  37.             int[,] arr = new int[a, a];
  38.             if (a % 2 != 0)
  39.                 Fill1(arr);
  40.             else
  41.                 Fill2(arr);
  42.             for (int i = 0; i < arr.GetLength(0); i++)
  43.             {
  44.                 for (int j = 0; j < arr.GetLength(1); j++)
  45.                 {
  46.                     Console.Write(arr[i, j]);
  47.                 }
  48.                 Console.WriteLine();
  49.             }
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment