Bob103

Для Елизаветы 2

Feb 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <locale.h>
  4. #include <algorithm>
  5. //#include "iomanip"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.  
  11. {
  12.  
  13. int size;
  14. printf("Enter array size\n");
  15. scanf("%d", &size);
  16. int *a = new int[size];
  17. printf("Enter elements of array\n");
  18. for (int i = 0; i < size; i++)
  19. {
  20. scanf("%d", &a[i]);
  21. }
  22. for (int i = 0; i < size; i+=2)
  23. {
  24. if(a[i]>0)
  25. {
  26. int minIndex = i;
  27. for (int j = i + 2; j < size; j += 2)
  28. {
  29. if (a[j] < a[minIndex])
  30. {
  31. minIndex = j;
  32. }
  33. }
  34. swap (a[i], a[minIndex]);
  35. }
  36. }
  37. printf("Output array\n");
  38. for (int i = 1; i < size; i += 2)
  39. {
  40. printf("%d ", a[i]);
  41. }
  42. system ("pause");
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment