using System using System Collections Generic using System Linq using

 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication2
{
class Lab1
{
private const int N = 9;
public int[] a = new int[N];
public int[] a2 = new int[N];
private int k = 0;
public Lab1()
{
Random rand = new Random();
for (int i = 0; i < N; i++)
a[i] = rand.Next(0, 20);
}
private void Swap(int i, int j)
{
int temp = a2[i];
a2[i] = a2[j];
a2[j] = temp;
}
public string print(int[] arr)
{
string NewText = "";
int buff = N;
if (arr == a2)
{
buff = k;
}
for (int i = 0; i < buff; i++)
{
NewText += arr[i];
NewText += "\r\n";
}
return NewText;
}
public void Solu()
{
for (int i = 0; i < N; i++)
{
int buff = a[i + 2];
a[i + 2] = a[i];
a[i] = buff;
i += 2;
}
for (int i = 1; i < N; i++)
{
a2[k] = a[i];
i += 2;
k++;
}
}
public void swp()
{
for (int i = 0; i < k; i++)
for (int j = i + 1; j < k; j++)
if (a2[j] < a2[i])
this.Swap(i, j);
}
}
}