Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int* form_mas(int count){
- int* massive = new int[count];
- int a=0;
- time_t t;
- srand((unsigned)time(&t));
- while (a < count){
- massive[a] = rand();
- cout << "massive [" << a << "] = " << massive[a] << endl;
- a++;
- }
- return massive;
- }
- void init_mas(int massive[],int count){
- int a = 0;
- for (int i = -1; i < count; i++){
- if ((count - 1) % 2 == 0){
- for (int j = count - 1; j >= i; j -= 2){
- if (massive[j] < massive[j - 2])
- {
- int r = massive[j];
- massive[j] = massive[j - 2];
- massive[j - 2] = r;
- }
- }
- }
- else {
- for (int j = count - 2; j >= i; j -= 2){
- if (massive[j] < massive[j - 2])
- {
- int r = massive[j];
- massive[j] = massive[j - 2];
- massive[j - 2] = r;
- }
- }
- }
- }
- }
- void print_mas(int massive[], int count){
- cout << "Массив после обработки" << endl;
- for (int i = 0; i <= count - 1; i++){
- cout << "massive [" << i << "] = " << massive[i] << endl;
- }
- }
- void main(){
- int num, k;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во элементов в массиве ";
- cin >> num;
- int* mas = form_mas(num);
- init_mas(mas, num);
- print_mas(mas, num);
- }
Advertisement
Add Comment
Please, Sign In to add comment