Advertisement
isotonicq

jeden

Jan 29th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 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 Korki29
  8. {
  9.     class Matrix
  10.     {
  11.         public double[,] table { get; set; }
  12.  
  13.         public Matrix(int x, int y)
  14.         {
  15.             table = new double[x, y];
  16.             FillTable();
  17.         }
  18.  
  19.         public void FillTable()
  20.         {
  21.             var random = new Random();
  22.  
  23.             for (int x = 0; x < table.GetLength(0); x++)
  24.             {
  25.                 for (int y = 0; y < table.GetLength(1); y++)
  26.                 {
  27.                     table[x, y] = random.Next(1, 9);
  28.                     Console.Write($"{table[x, y]} ");
  29.                 }
  30.                 Console.WriteLine();
  31.             }
  32.         }
  33.  
  34.         public void CheckCol()
  35.         {
  36.             var sumy = new List<double>();
  37.             for (int x = 0; x < table.GetLength(1); x++)
  38.             {
  39.                 double sum = 0;
  40.                 for (int y = 0; y < table.GetLength(0); y++)
  41.                 {
  42.                     sum += table[y, x];
  43.                 }
  44.                 Console.WriteLine(sum);
  45.                 sumy.Add(sum);
  46.             }
  47.  
  48.             var result = sumy.Max() / table.GetLength(1);
  49.  
  50.             Console.WriteLine($"\n{result}");
  51.         }
  52.     }
  53.     class Program
  54.     {
  55.         static void Main(string[] args)
  56.         {
  57.             var table = new Matrix(5, 5);
  58.             table.CheckCol();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement