Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include "locale.h"
- #define m 10
- #define n 10
- using namespace std;
- bool noSwap;
- void vvod_arr(int h, int x[])
- {
- int i, l;
- cout « "Введите количество элементов массива" « endl;
- cin » l;
- cout « "Ввод массива" « endl;
- for (i = 0; i < l; i++)
- {
- cin » x[i];
- }
- }
- int vvod_arr_rand(int h, int x[])
- {
- int i;
- for (i = 0; i < h; i++)
- {
- x[i] = -10000 + rand() % 20000;
- cout « x[i] « " ";
- }
- cout « endl;
- return 0;
- }
- void vivod_arr(int h, int x[])
- {
- int i;
- cout « "Вывод массива" « endl;
- for (i = 0; i < h; i++)
- {
- cout « x[i] « " ";
- }
- }
- void por(int h, int x[])
- {
- int i, tmp, j = 0;
- for (i = h - 1; i >= 0; i--)
- {
- noSwap = 1;
- for (j = 0; j < i; j++)
- {
- if (x[j] > x[j + 1])
- {
- tmp = x[j];
- x[j] = x[j + 1];
- x[j + 1] = tmp;
- noSwap = 0;
- }
- }
- if (noSwap == 1)
- {
- break;
- }
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int a[n], b[m], k;
- setlocale(LC_ALL, "rus");
- cout « "Для ввода массива с клавиатуры введите 1, для ввода случайных чисел нажмите 0" « endl;
- cin » k;
- //Ввод массива
- if (k == 1)
- {
- vvod_arr(n, a);
- vvod_arr(m, b);
- }
- else
- {
- vvod_arr_rand(n, a);
- vvod_arr_rand(m, b);
- }
- //Упорядочивание массива от меньшего к большему
- por(n, a);
- por(m, b);
- //Вывод массива
- vivod_arr(n, a);
- cout « endl;
- vivod_arr(m, b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement