Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include "pch.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <Windows.h>
  6. #include <cmath>
  7. #include <string>
  8. #include <locale.h>
  9. #include <iostream>
  10. #include <time.h>
  11.  
  12. HANDLE hConsole;
  13. void show(int a[], int n, int el1, int el2, int color)
  14. {
  15.     system("cls");
  16.  
  17.     for (int i = 0; i < n; ++i) {
  18.         if (i == el1 || i == el2) {
  19.             SetConsoleTextAttribute(hConsole, color);
  20.             printf("%5i\n", a[i]);
  21.         }
  22.         else {
  23.             SetConsoleTextAttribute(hConsole, 10);
  24.             printf("%i\n", a[i]);
  25.         }
  26.     }
  27.  
  28.     Sleep(100);
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34.     setlocale(LC_ALL, "");
  35.     system("color 05");
  36.     hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  37.  
  38.  
  39.     const int N = 10;
  40.     int a[N];
  41.     srand((unsigned)time(0));
  42.     for (int i = 0; i < N; i++)
  43.     {
  44.         a[i] = 1 + rand() % 51;
  45.         SetConsoleTextAttribute(hConsole, 3);
  46.         printf("%d ", a[i]);
  47.         printf("\n");
  48.         Sleep(150);
  49.     }
  50.  
  51.  
  52.     int t;
  53.     for (int i = 0; i < N - 1; ++i)
  54.     {
  55.         for (int j = i + 1; j < N; ++j) {
  56.             show(a, N, i, j, 6);
  57.             if (a[i] > a[j])
  58.             {
  59.                 t = a[i];
  60.                 a[i] = a[j];
  61.                 a[j] = t;
  62.                 show(a, N, i, j, 13);
  63.             }
  64.             else {
  65.                 show(a, N, i, j, 15);
  66.             }
  67.         }
  68.  
  69.     }
  70.     system("cls");
  71.     for (int i = 0; i < N; i++)
  72.     {
  73.  
  74.         SetConsoleTextAttribute(hConsole, 3);
  75.         printf("%d ", a[i]);
  76.         printf("\n");
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement