Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <time.h>
- using namespace std;
- int ar[50];
- int sort()
- {
- int amount = 0;
- for (int i = 0; i < 50; i++)
- for (int j = 0; j < 50 - 1; j++)
- if (ar[j] > ar[j + 1])
- {
- int tmp = ar[j];
- ar[j] = ar[j + 1];
- ar[j + 1] = tmp;
- amount++;
- }
- return amount;
- }
- int main()
- {
- srand(time(NULL));
- for (int i = 0; i < 50; i++)
- ar[i] = rand() % 100;
- cout << sort() << endl;
- for (int i = 0; i < 50; i++)
- cout << ar[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement