Polnochniy

Untitled

Nov 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int main()
  5. {
  6. setlocale(LC_ALL, "Rus");
  7. int N;
  8. cout << "Введите число элементов " << endl;
  9. cin >> N;
  10. int* a = new int[N];
  11. cout << "Введите элементы массива " << endl;
  12. for (int t = 0; t < N; t++)
  13. {
  14. cin >> a[t];
  15. }
  16. for (int i = 0; i < N - 1; i++)
  17. {
  18. int min = i;
  19. for (int max = i + 1; max < N; max++)
  20. {
  21. if (a[max] < a[min])
  22. {
  23. min = max;
  24. }
  25. }
  26. swap(a[i], a[min]);
  27. }
  28. cout << "Результат сортировки равен : ";
  29. for (int t = 0; t < N; t++)
  30. {
  31. cout << a[t] << " ";
  32. }
  33. delete[] a;
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment