TargeTPoweR

Строки и Столбцы Массивов

Mar 25th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 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 Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int secondLineSum = 0;
  14. int firstColumnMultiply = 1;
  15.  
  16. int[,] array = {
  17. {1, 2, 3, 4},
  18. {5, 6, 7, 8},
  19. {9, 1, 2, 3},
  20. {4, 5, 6, 7} };
  21. Console.WriteLine("Исходная матрица выглядить так:");
  22. Console.WriteLine(" ");
  23. for (int i = 0; i < array.GetLength(0); i++)
  24. {
  25. for (int j = 0; j < array.GetLength(1); j++)
  26. {
  27. Console.Write(array[i, j] + " ");
  28. }
  29. Console.WriteLine();
  30. }
  31.  
  32. Console.WriteLine(" ");
  33. Console.WriteLine("Введите номер строки :");
  34. int getLineNumber = Convert.ToInt32(Console.ReadLine());
  35.  
  36. for (int k = 0; k < array.GetLength(0); k++)
  37. {
  38. secondLineSum += array[getLineNumber - 1, k];
  39. }
  40. Console.WriteLine("Сумма чисел во второй строке равна: " + secondLineSum);
  41.  
  42. Console.WriteLine(" ");
  43. Console.WriteLine("Введите номер столбца :");
  44. int getColumnNumber = Convert.ToInt32(Console.ReadLine());
  45.  
  46. for (int v = 0; v < array.GetLength(0); v++)
  47. {
  48. firstColumnMultiply *= array[v, getColumnNumber - 1];
  49. }
  50. Console.WriteLine("Произведение чисел в первом столбце равно: " + firstColumnMultiply);
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment