OldBeliver

Array_01

Mar 13th, 2021 (edited)
94
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 CSharpArray2D
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int lineSize = 4;
  14.             int columnSize = 3;
  15.             int lowerLimit = 1;
  16.             int upperLimit = 6;
  17.             int[,] array2D = new int[lineSize, columnSize];
  18.             Random rand = new Random();
  19.             int line;
  20.             int lineSum = 0;
  21.             int column;
  22.             int columnMultiplication = 1;
  23.  
  24.             Console.WriteLine($"Имеется двухмерный массив {lineSize} на {columnSize}, заполненный случайными числами от {lowerLimit} до {upperLimit - 1}");
  25.             for (int i = 0; i < array2D.GetLength(0); i++)
  26.             {
  27.                 for (int j = 0; j < array2D.GetLength(1); j++)
  28.                 {
  29.                     array2D[i, j] = rand.Next(lowerLimit, upperLimit);
  30.                     Console.Write($" {array2D[i, j]}");
  31.                 }
  32.                 Console.WriteLine();
  33.             }
  34.  
  35.             Console.Write($"Введите номер строки от 1 до {lineSize}, чтобы посчитать сумму чисел: ");
  36.             line = Convert.ToInt32(Console.ReadLine()) - 1;
  37.             if (0 >= line || line <= lineSize)
  38.             {
  39.                 for (int i = 0; i < array2D.GetLength(1); i++)
  40.                 {
  41.                     lineSum += array2D[line, i];
  42.                 }                
  43.                 Console.WriteLine($"Сумма чисел {line+1}-й строки равна {lineSum}");
  44.             }
  45.            
  46.             Console.Write($"Введите номер столбца от 1 до {columnSize}, чтобы посчитать произведение столбца: ");
  47.             column = Convert.ToInt32(Console.ReadLine())-1;
  48.             if (0>= column || column <= columnSize)
  49.             {
  50.                 for (int i = 0; i < array2D.GetLength(0); i++)
  51.                 {
  52.                     columnMultiplication *= array2D[i,column];
  53.                 }
  54.                 Console.WriteLine($"Произведение чисел {column + 1}-го столбца равно {columnMultiplication}");
  55.             }
  56.         }
  57.     }
  58. }
  59.  
Add Comment
Please, Sign In to add comment