-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
108 lines (90 loc) · 3.47 KB
/
Program.cs
File metadata and controls
108 lines (90 loc) · 3.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Задача 47. Задайте двумерный массив размером m×n,
// заполненный случайными вещественными числами.
// m = 3, n = 4.
// 0,5 7 -2 -0,2
// 1 -3,3 8 -9,9
// 8 7,8 -7,1 9
// Console.WriteLine("Введите число m");
// int m = Convert.ToInt32(Console.ReadLine());
// Console.WriteLine("Введите число n");
// int n = Convert.ToInt32(Console.ReadLine());
// double[,] array = new double[m, n];
// for (int i = 0; i < array.GetLength(0); i++)
// {
// for (int j = 0; j < array.GetLength(0); j++)
// {
// array[i, j] = Math.Round ((new Random().Next(-50, 50) + new Random().NextDouble()), 1);
// Console.Write($"{array[i, j]} ");
// }
// Console.WriteLine("");
// }
// Задача 50. Напишите программу, которая на вход принимает позиции элемента в двумерном массиве,
// и возвращает значение этого элемента или же указание, что такого элемента нет.
// Например, задан массив:
// 1 4 7 2
// 5 9 2 3
// 8 4 2 4
// 17 -> такого числа в массиве нет
// Console.WriteLine("Введите число m");
// int m = Convert.ToInt32(Console.ReadLine());
// Console.WriteLine("Введите число n");
// int n = Convert.ToInt32(Console.ReadLine());
// int[,] matr = new int[m, n];
// 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, 50);
// Console.Write($"{matr[i, j]} ");
// }
// Console.WriteLine("");
// }
// Console.WriteLine("Введите позицию элемента x");
// int x = Convert.ToInt32(Console.ReadLine());
// Console.WriteLine("Введите позицию элемента y");
// int y = Convert.ToInt32(Console.ReadLine());
// for (int i = 0; i < matr.GetLength(0); i++)
// {
// for (int j = 0; j < matr.GetLength(1); j++)
// {
// if (i == x && j == y)
// {
// Console.WriteLine($"Значение элемента = {matr[i, j]}");
// }
// else
// {
// Console.WriteLine("Такого элемента нет");
// }
// }
// }
// Задача 52. Задайте двумерный массив из целых чисел.
// Найдите среднее арифметическое элементов в каждом столбце.
// Например, задан массив:
// 1 4 7 2
// 5 9 2 3
// 8 4 2 4
// Среднее арифметическое каждого столбца: 4,6; 5,6; 3,6; 3.
Console.WriteLine("Введите число m");
int m = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите число n");
int n = Convert.ToInt32(Console.ReadLine());
int[,] matr = new int[m, n];
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);
Console.Write($"{matr[i, j]} ");
}
Console.WriteLine("");
}
for (int j = 0; j < matr.GetLength(1); j++)
{
double avg = 0;
for (int i = 0; i < matr.GetLength(0); i++)
{
avg = avg + matr[i, j];
}
avg = Math.Round(avg / m, 2);
Console.WriteLine($"{avg} ");
}