Pandarec13

сортировка

Dec 7th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4. int main() {
  5. srand(time(0));
  6. setlocale(LC_ALL, "");
  7. int a;
  8. cout << "Введите размер массива : ";
  9. cin >> a;
  10. int *mas = new int [a];
  11. cout << "Введите массив : " << endl;
  12.  
  13. for (int i = 0; i < a; i++) {
  14. mas[i]= (-20+rand() %100);
  15. }
  16. for (int i = 0; i < a; i++) {
  17. cout << mas[i] << " ";
  18. }
  19. cout << endl;
  20. for (int i = 0; i < a; i++) {
  21. for (int p = 0; p < a; p++) {
  22. if (mas[p] < mas[i] && mas[i]>0 && mas[p]>0) {
  23. int temp = 0;
  24. temp = mas[p];
  25. mas[p] = mas[i];
  26. mas[i] = temp;
  27. }
  28.  
  29. }
  30. }
  31.  
  32. for (int i = 0; i < a; i++) {
  33. cout << mas[i]<< " ";
  34. }
  35. system("pause");
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment