MayloGreen

DZ_Array2D

May 9th, 2021 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DZ_Array
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Random random = new Random();
  10.  
  11.             int[,] array = new int [4, 5];
  12.             int numberColumn = 0;
  13.             int numberLine = 1;
  14.             int additionResult = 0;
  15.             int multiplicationResult = 1;
  16.            
  17.             for (int i = 0; i < array.GetLength(0); i++)
  18.             {
  19.                 for (int j = 0; j < array.GetLength(1); j++)
  20.                 {
  21.                     array[i, j] = random.Next(1, 9);
  22.                     Console.Write(array[i, j] + " ");
  23.                 }
  24.                 Console.WriteLine();
  25.             }
  26.  
  27.             for (int i = 0; i < array.GetLength(0); i++)
  28.             {
  29.                 multiplicationResult *= array[i, numberColumn];
  30.             }
  31.  
  32.             for (int i = 0; i < array.GetLength(1); i++)
  33.             {
  34.                 additionResult += array[numberLine, i];
  35.             }
  36.  
  37.             Console.WriteLine($"Результат сложения 2 строки: {additionResult}");
  38.             Console.WriteLine($"Результат умножения 1 столбца: {multiplicationResult}");
  39.             Console.ReadLine();
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment