--- C# 7.3 ---
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSLear
{
class Program
private const int Row = 5;
private const int Cols = 6;
static void Main(string[] args)
int[,] RandomArray = new int[Row, Cols];
ArrayRandomize(ref RandomArray, Row, Cols);
Console.WriteLine("Average for each Column:\n");
foreach (double Average in ColumAverage(RandomArray, Row, Cols))
Console.WriteLine(Average);
}
Console.WriteLine("Min-Max for each Row:\n");
foreach(var Pair in RowMinMax(RandomArray, Row, Cols))
Console.WriteLine($"Min: {Pair.Item1}:: Max: {Pair.Item2}");
Console.ReadKey();
public static IEnumerable<double> ColumAverage(int[,] Arr, int ArrRows, int ArrCols)
IList<int> Temp = new List<int>();
for (int i = 0; i < ArrCols; i++)
for (int j = 0; j < ArrRows; j++)
Temp.Add(Arr[j, i]);
yield return Temp.Average();
Temp.Clear();
public static IEnumerable<Tuple<int, int>> RowMinMax(int[,] Arr, int ArrRows, int ArrCols)
yield return new Tuple<int,int>(Temp.Min(), Temp.Max());
public static void ArrayRandomize(ref int[,] Arr, int ArrRows, int ArrCols)
Random r = new Random();
for (int i = 0; i < ArrRows; i++)
for (int j = 0; j < ArrCols; j++)
Arr[i, j] = r.Next(-99, 99);
Объяснение:
--- C# 7.3 ---
using System;
using System.Collections.Generic;
using System.Linq;
namespace CSLear
{
class Program
{
private const int Row = 5;
private const int Cols = 6;
static void Main(string[] args)
{
int[,] RandomArray = new int[Row, Cols];
ArrayRandomize(ref RandomArray, Row, Cols);
Console.WriteLine("Average for each Column:\n");
foreach (double Average in ColumAverage(RandomArray, Row, Cols))
{
Console.WriteLine(Average);
}
Console.WriteLine("Min-Max for each Row:\n");
foreach(var Pair in RowMinMax(RandomArray, Row, Cols))
{
Console.WriteLine($"Min: {Pair.Item1}:: Max: {Pair.Item2}");
}
Console.ReadKey();
}
public static IEnumerable<double> ColumAverage(int[,] Arr, int ArrRows, int ArrCols)
{
IList<int> Temp = new List<int>();
for (int i = 0; i < ArrCols; i++)
{
for (int j = 0; j < ArrRows; j++)
{
Temp.Add(Arr[j, i]);
}
yield return Temp.Average();
Temp.Clear();
}
}
public static IEnumerable<Tuple<int, int>> RowMinMax(int[,] Arr, int ArrRows, int ArrCols)
{
IList<int> Temp = new List<int>();
for (int i = 0; i < ArrCols; i++)
{
for (int j = 0; j < ArrRows; j++)
{
Temp.Add(Arr[j, i]);
}
yield return new Tuple<int,int>(Temp.Min(), Temp.Max());
Temp.Clear();
}
}
public static void ArrayRandomize(ref int[,] Arr, int ArrRows, int ArrCols)
{
Random r = new Random();
for (int i = 0; i < ArrRows; i++)
{
for (int j = 0; j < ArrCols; j++)
{
Arr[i, j] = r.Next(-99, 99);
}
}
}
}
}
Объяснение: