-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask03.cs
More file actions
41 lines (33 loc) · 991 Bytes
/
Copy pathtask03.cs
File metadata and controls
41 lines (33 loc) · 991 Bytes
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
// Задайте массив вещественных чисел.
// Найдите разницу между максимальным и минимальным элементов
// массива.
// [3 7 22 2 78] -> 76
int n = 6;
double[] Array(int n)
{
double[] arr = new double[n];
for (int i = 0; i < arr.Length; i++)
arr[i] = new Random().NextDouble();
return arr;
}
double[] MaxDiffMin(double[] arr)
{
double max = arr.Max();
double min = arr.Min();
double[] diff = new double[1];
for (int i = 0; i < arr.Length; i++)
diff[0] = max - min;
return diff;
}
void PrintArray(double[] arr)
{
Console.WriteLine();
for (int k = 0; k < arr.Length; k++)
Console.Write($"{arr[k]} ");
Console.WriteLine();
}
Console.Write($"Massive: ");
double[] array = Array(n);
PrintArray(array);
Console.Write($"Difference between max and min is: ");
PrintArray(MaxDiffMin(array));