TargeTPoweR

Массивы: сложение строки и произведение столбца

Mar 25th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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 LineNumber = Convert.ToInt32(Console.ReadLine());
  35.  
  36. for (int i = 0; i < array.GetLength(0); i++)
  37. {
  38. secondLineSum += array[LineNumber - 1, i];
  39. }
  40. Console.WriteLine("Сумма чисел во второй строке равна: " + secondLineSum);
  41.  
  42. Console.WriteLine(" ");
  43. Console.WriteLine("Введите номер столбца :");
  44. int columnNumber = Convert.ToInt32(Console.ReadLine());
  45.  
  46. for (int j = 0; j < array.GetLength(0); j++)
  47. {
  48. firstColumnMultiply *= array[j, columnNumber - 1];
  49. }
  50. Console.WriteLine("Произведение чисел в первом столбце равно: " + firstColumnMultiply);
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment