AdemDev

Работа с конкретными строками/столбцами

Aug 31st, 2023 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp
  4. {
  5. internal class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int rowForSumm = 2;
  10. int collumForMultiply = 1;
  11.  
  12. Console.WriteLine($"Программа генерирует случайный массив и выводит сумму элементов строки {rowForSumm} и произведение элементов столбца {collumForMultiply}");
  13.  
  14. int rowsCount = 3;
  15. int columnsCount = 3;
  16. int[,] array = new int[rowsCount, columnsCount];
  17. int minValue = 0;
  18. int maxValue = 9;
  19. Random random = new Random();
  20.  
  21. int sumResult = 0;
  22. int mltiplyResult = 1;
  23.  
  24. Console.WriteLine("Сгенерированный массив:");
  25.  
  26. for (int i = 0; i < array.GetLength(0); i++)
  27. {
  28. for (int j = 0; j < array.GetLength(1); j++)
  29. {
  30. array[i, j] = random.Next(minValue, maxValue + 1);
  31. Console.Write(array[i, j] + " ");
  32. }
  33. Console.WriteLine();
  34. }
  35.  
  36. for (int i = 0; i < array.GetLength(0); i++)
  37. mltiplyResult *= array[i, collumForMultiply - 1];
  38.  
  39. for (int j = 0; j < array.GetLength(1); j++)
  40. sumResult += array[rowForSumm - 1, j];
  41.  
  42. Console.WriteLine($"Сумма элементов строки {rowForSumm}: {sumResult}\nПроизведение элементов столбца {collumForMultiply}: {mltiplyResult}");
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment