Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CSharpArray2D
- {
- class Program
- {
- static void Main(string[] args)
- {
- int lineSize = 4;
- int columnSize = 3;
- int lowerLimit = 1;
- int upperLimit = 6;
- int[,] array2D = new int[lineSize, columnSize];
- Random rand = new Random();
- int line;
- int lineSum = 0;
- int column;
- int columnMultiplication = 1;
- Console.WriteLine($"Имеется двухмерный массив {lineSize} на {columnSize}, заполненный случайными числами от {lowerLimit} до {upperLimit - 1}");
- for (int i = 0; i < array2D.GetLength(0); i++)
- {
- for (int j = 0; j < array2D.GetLength(1); j++)
- {
- array2D[i, j] = rand.Next(lowerLimit, upperLimit);
- Console.Write($" {array2D[i, j]}");
- }
- Console.WriteLine();
- }
- Console.Write($"Введите номер строки от 1 до {lineSize}, чтобы посчитать сумму чисел: ");
- line = Convert.ToInt32(Console.ReadLine()) - 1;
- if (0 >= line || line <= lineSize)
- {
- for (int i = 0; i < array2D.GetLength(1); i++)
- {
- lineSum += array2D[line, i];
- }
- Console.WriteLine($"Сумма чисел {line+1}-й строки равна {lineSum}");
- }
- Console.Write($"Введите номер столбца от 1 до {columnSize}, чтобы посчитать произведение столбца: ");
- column = Convert.ToInt32(Console.ReadLine())-1;
- if (0>= column || column <= columnSize)
- {
- for (int i = 0; i < array2D.GetLength(0); i++)
- {
- columnMultiplication *= array2D[i,column];
- }
- Console.WriteLine($"Произведение чисел {column + 1}-го столбца равно {columnMultiplication}");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment