-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask52
More file actions
54 lines (47 loc) · 1.56 KB
/
Task52
File metadata and controls
54 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Задача 52. Задайте двумерный массив из целых чисел.
// Найдите среднее арифметическое элементов в каждом столбце.
// Например, задан массив:
// 1 4 7 2
// 5 9 2 3
// 8 4 2 4
// Среднее арифметическое каждого столбца: 4,6; 5,6; 3,6; 3.
Console.Write("Введите количество строк в массиве: ");
int rows = int.Parse(Console.ReadLine());
Console.Write("Введите количество стоблцов в массиве: ");
int columns = int.Parse(Console.ReadLine());
int[,] myArray = GetArray(rows, columns, 0, 10); //start, end
Console.WriteLine("");
PrintArray(myArray);
Console.WriteLine("");
for (int i = 0; i < columns; i++)
{
double average = 0;
for (int j = 0; j < rows; j++)
{
average += myArray[j, i];
}
Console.WriteLine($"Cреднее арифметическое элементов столбца {i + 1} = {average / rows:F2}");
}
int[,] GetArray(int m, int n, int minValue, int maxValue)
{
int[,] result = new int[m, n];
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
result[i, j] = new Random().Next(minValue, maxValue + 1);
}
}
return result;
}
void PrintArray(int[,] inArray)
{
for (int i = 0; i < inArray.GetLength(0); i++)
{
for (int j = 0; j < inArray.GetLength(1); j++)
{
Console.Write($"{inArray[i, j]} ");
}
Console.WriteLine();
}
}