Advertisement
filin

laba_4_z_3_mk1

Sep 25th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Z_3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "определить количество четных элементов, расположенных ниже главной диагонали;";
  14.             Console.Write("Ведите натуральное число, n= ");
  15.             int n = int.Parse(Console.ReadLine());
  16.             Console.Write("Ведите натуральное число, m= ");
  17.             int m = int.Parse(Console.ReadLine());
  18.             int[,] arr = new int[n, n];
  19.             fillingArray(ref arr, n, m);
  20.             display1(arr, n, m);
  21.             delimiter(m);
  22.             display2(arr, n, m);
  23.             Console.ReadKey();
  24.         }
  25.         static void fillingArray(ref int[,] arr, int n, int m)
  26.         {
  27.             Random Rand = new Random();
  28.             for (int i = 0; i < n; i++)
  29.             {
  30.                 for (int j = 0; j < m; j++)
  31.                 {
  32.                     arr[i, j] = Rand.Next(9);
  33.                 }
  34.             }
  35.         }
  36.         static void display1(int[,] arr, int n, int m)
  37.         {
  38.             for (int i = 0; i < n; i++)
  39.             {
  40.                 for (int j = 0; j < m; j++)
  41.                 {
  42.                     Console.Write("{0} ", arr[i, j]);
  43.                 }
  44.                 Console.WriteLine();
  45.             }
  46.         }
  47.         static void display2(int[,] arr, int n, int m)
  48.         {
  49.             for (int i = n - 1; i >= 0; i--)
  50.             {
  51.                 for (int j = 0; j < m; j++)
  52.                 {
  53.                     Console.Write("{0} ", arr[i, j]);
  54.                 }
  55.                 if (i != 0)
  56.                 {
  57.                     Console.WriteLine();
  58.                     i--;
  59.                     for (int j = m-1; j >=0 ; j--)
  60.                     {
  61.                         Console.Write("{0} ", arr[i, j]);
  62.                     }
  63.                     Console.WriteLine();
  64.                 }
  65.  
  66.             }
  67.         }
  68.         static void delimiter(int a)
  69.         {
  70.             for (int i = 0; i < a; i++)
  71.             {
  72.                 Console.Write("* ");
  73.             }
  74.             Console.WriteLine();
  75.         }
  76.  
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement