Bob103

для данилы

Feb 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include "iostream"
  2. #include "stdlib.h"
  3. #include "iomanip"
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8.  
  9. {
  10. setlocale(LC_CTYPE,"Russian");
  11.  
  12. int size;
  13. cout << "Введите размер массива ";
  14. cin >> size;
  15. int *a = new int[size];
  16. cout << "Введите элементы массива \n" ;
  17. for (int i = 0; i < size; i++)
  18. {
  19. cin >> a[i];
  20. }
  21. for (int i = 0; i < size; i+=2)
  22. {
  23. if(a[i]>0)
  24. {
  25. int minIndex = i;
  26. for (int j = i + 2; j < size; j += 2)
  27. {
  28. if (a[j] < a[minIndex])
  29. {
  30. minIndex = j;
  31. }
  32. }
  33. swap (a[i], a[minIndex]);
  34. }
  35. }
  36. cout <<"Вывод массива \n";
  37. for (int i = 1; i < size; i += 2)
  38. {
  39. cout << a[i] << ' ';
  40. }
  41. system ("pause");
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment