Advertisement
junniorrkaa

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

Sep 15th, 2024 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | Source Code | 0 0
  1. using System;
  2.  
  3. namespace CSLight
  4. {
  5.     internal class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[,] matrix = {
  10.  
  11.                 { 1, 2, 3, 4, 5 },
  12.                 { 5, 4, 3, 2, 1 },
  13.                 { 1, 2, 3, 4, 5 }
  14.  
  15.             };
  16.  
  17.             int сolumnsProduct = 1;
  18.             int columnIndex = 0;
  19.             int lineSum = 0;
  20.             int lineIndex = 1;
  21.  
  22.             for (int i = 0; i < matrix.GetLength(0); i++)
  23.             {
  24.                 for (int j = 0; j < matrix.GetLength(1); j++)
  25.                 {
  26.                     Console.Write(matrix[i, j] + " ");
  27.                 }
  28.  
  29.                 Console.WriteLine();
  30.             }
  31.  
  32.             for (int i = 0; i < matrix.GetLength(0); i++)
  33.             {
  34.                 сolumnsProduct *= matrix[i, columnIndex];
  35.             }
  36.  
  37.             for (int i = 0; i < matrix.GetLength(1); i++)
  38.             {
  39.                 lineSum += matrix[lineIndex, i];
  40.             }
  41.  
  42.             Console.WriteLine("\nПроизведение столбцов: " + сolumnsProduct);
  43.             Console.WriteLine("\nСумма строки: " + lineSum);
  44.             Console.ReadLine();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement