fork download
  1. using System;
  2. using System.Threading;
  3.  
  4. namespace ConsoleApplication7
  5. {
  6. internal class Program
  7. {
  8. private static void Main(string[] args)
  9. {
  10. int m = 4;
  11. int n = 6;
  12.  
  13. Random rnd=new Random();
  14.  
  15. var matrix = new int[m, n];
  16.  
  17. for (int i = 0; i < matrix.GetLength(0); i++)
  18. {
  19. for (int j = 0; j < matrix.GetLength(1); j++)
  20. {
  21. matrix[i, j] = rnd.Next(1, 9);
  22. Console.Write($"{matrix[i,j]} ");
  23. }
  24.  
  25. Console.WriteLine();
  26. }
  27. int sum = 0;
  28. for (int i = 1; i < matrix.GetLength(1); i+=2)
  29. {
  30. for (int j = 0; j < matrix.GetLength(0); j++)
  31. {
  32. sum += matrix[j, i];
  33. }
  34. Console.WriteLine("Сумма {0} //{1}столбец",sum,i+1);
  35. sum = 0;
  36. }
  37.  
  38. }
  39.  
  40. }
  41. }
Success #stdin #stdout 0.04s 23952KB
stdin
Standard input is empty
stdout
7 2 8 8 2 6 
1 4 5 6 7 5 
6 8 1 6 1 7 
7 7 3 7 4 4 
Сумма 21 //2столбец
Сумма 27 //4столбец
Сумма 22 //6столбец