Advertisement
evgenius

Untitled

May 29th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int ar[50];
  8.  
  9. int sort()
  10. {
  11.     int amount = 0;
  12.     for (int i = 0; i < 50; i++)
  13.         for (int j = 0; j < 50 - 1; j++)
  14.             if (ar[j] > ar[j + 1])
  15.             {
  16.                 int tmp = ar[j];
  17.                 ar[j] = ar[j + 1];
  18.                 ar[j + 1] = tmp;
  19.                 amount++;
  20.             }
  21.     return amount;
  22. }
  23. int main()
  24. {
  25.     srand(time(NULL));
  26.     for (int i = 0; i < 50; i++)
  27.         ar[i] = rand() % 100;
  28.     cout << sort() << endl;
  29.     for (int i = 0; i < 50; i++)
  30.         cout << ar[i] << " ";
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement