Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <Windows.h>
- #include <cmath>
- #include <string>
- #include <locale.h>
- #include <iostream>
- #include <time.h>
- HANDLE hConsole;
- void show(int a[], int n, int el1, int el2, int color)
- {
- system("cls");
- for (int i = 0; i < n; ++i) {
- if (i == el1 || i == el2) {
- SetConsoleTextAttribute(hConsole, color);
- printf("%5i\n", a[i]);
- }
- else {
- SetConsoleTextAttribute(hConsole, 10);
- printf("%i\n", a[i]);
- }
- }
- Sleep(100);
- }
- int main()
- {
- setlocale(LC_ALL, "");
- system("color 05");
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- const int N = 10;
- int a[N];
- srand((unsigned)time(0));
- for (int i = 0; i < N; i++)
- {
- a[i] = 1 + rand() % 51;
- SetConsoleTextAttribute(hConsole, 3);
- printf("%d ", a[i]);
- printf("\n");
- Sleep(150);
- }
- int t;
- for (int i = 0; i < N - 1; ++i)
- {
- for (int j = i + 1; j < N; ++j) {
- show(a, N, i, j, 6);
- if (a[i] > a[j])
- {
- t = a[i];
- a[i] = a[j];
- a[j] = t;
- show(a, N, i, j, 13);
- }
- else {
- show(a, N, i, j, 15);
- }
- }
- }
- system("cls");
- for (int i = 0; i < N; i++)
- {
- SetConsoleTextAttribute(hConsole, 3);
- printf("%d ", a[i]);
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement