Код программы

Хід роботи.

 

Водяницкий

5. Дан вектор (N+15) отсортировать четные числа по возрастанию (нечетные оставить на своих местах) числа генерировать случайно в интервале [-N-15; N+15]

Код программы

#include "stdafx.h"

#include <iostream>

#include <math.h>

using namespace std;

int main()

{

int array[20];

for (int i = 0; i < 20; i++)

{

array[i] = rand() % 41 - 20;

cout << array[i] << " ";

}

for (int i = 0; i < 20; i++)

{

if (array[i] % 2 == 0)

{

for (int j = 0; j < 20; j++)

if (array[j] % 2 == 0)

{

if (array[i] < array[j])

{

int t = array[i];

array[i] = array[j];

array[j] = t;

}

}

}

}

cout << endl << endl;

for (int i = 0; i < 20; i++)

{

cout << array[i] << " ";

}

system("pause");

return 0;

}

 

Результаты выполнения программы

КОСОЛАПОВ

16. Дана матрица (N+15)x(N+15) отсортировать по убыванию и записать результат в виде вертикальной нисходящей змейки, числа генерировать случайно в интервале [-N-15; N+15]

10 3 2

9 4 1

8 5 0

7 6 -1

Код программы

#include <iostream>

#include <math.h>

/#include <stdio.h>

#include "sortmass.h"

using namespace std;

 

int main()

{

int matr[29][29];

int matr[29][29] = new int[29][29];

matr = (int **) Cmatr;

int i, j;

 

{

cout << "UNSORTED MATRIX" << '\n';

func_gener(matr, 29,59,29);

 

cout << "SORTED MATRIX" << '\n';

func_sort(matr, 29);

 

for ( i = 0; i < 29; i++)

{

for ( j = 0; j < 29; j++)

{

cout << matr[i][j] << " ";

}

cout << endl;

}

 

system("PAUSE");

return 0;

 

}

}