include stdafx include iostream include conio include time define usin

 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
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <time.h>
#define N 9
using namespace std;
int a[N], a2[N];
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_CTYPE, "rus");
srand(time(NULL));
for (int i = 0; i < N; i++)
a[i] = 0 + rand() % 20;
cout << "Исходный массив:\n";
for (int i = 0; i < N; i++)
cout << "a[" << i + 1 << "] = " << a[i] << endl;
for (int i = 0; i < N; i++)
{
int buff = a[i + 2];
a[i + 2] = a[i];
a[i] = buff;
i += 2;
}
int k = 0;
for (int i = 1; i < N; i++)
{
a2[k] = a[i];
i += 2;
k++;
}
for (int i = 0; i < k; i++)
for (int j = i + 1; j < k; j++)
if (a2[j] < a2[i])swap(a2[i], a2[j]);
cout << "\nПреобразованный массив:\n\n";
for (int i = 0; i < N; i++)
cout << "a[" << i + 1 << "] = " << a[i] << endl;
cout << endl;
cout << "\nОтсортированный массив:\n\n";
for (int i = 0; i < k; i++)
cout << "a2[" << i + 1 << "] = " << a2[i] << endl;
_getch();
return 0;
}