-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask03.cs
More file actions
77 lines (62 loc) · 1.81 KB
/
Copy pathtask03.cs
File metadata and controls
77 lines (62 loc) · 1.81 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Задача 52. Задайте двумерный массив из целых чисел.
// Найдите среднее арифметическое элементов в каждом столбце.
// Например, задан массив:
// 1 4 7 2
// 5 9 2 3
// 8 4 2 4
// Среднее арифметическое каждого столбца: 4,6; 5,6; 3,6; 3.
Console.Write("Enter num row matrix: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter num columns matrix: ");
int m = Convert.ToInt32(Console.ReadLine());
void Matrix (int[,] matr)
{
for (int i = 0; i < matr.GetLength(0); i++)
{
for (int j = 0; j < matr.GetLength(1); j++)
{
matr[i, j] = new Random().Next(0,10);
}
}
}
void PrintMatrix(int[,] matr)
{
for (int i = 0; i < matr.GetLength(0); i++)
{
for (int j = 0; j < matr.GetLength(1); j++)
{
Console.Write($"{matr[i, j]} ");
}
Console.WriteLine();
}
}
double [] ArithmeticMeanColumns(int[,] arr)
{
double[] result = new double[arr.GetLength(1)];
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
result[j] += Convert.ToDouble(arr[i, j]);
}
}
for (int i = 0; i < result.Length; i++)
{
result[i] /= arr.GetLength(0);
}
return result;
}
void PrintArray(double[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
Console.Write($"{arr[i]} ");
}
}
int[,] matrix = new int [m , n];
Console.WriteLine($"Matrix: ");
Matrix(matrix);
PrintMatrix(matrix);
Console.WriteLine($"Array: ");
double[] arr = ArithmeticMeanColumns(matrix);
PrintArray(arr);