Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <locale.h>
- #include <algorithm>
- //#include "iomanip"
- using namespace std;
- int main()
- {
- int size;
- printf("Enter array size\n");
- scanf("%d", &size);
- int *a = new int[size];
- printf("Enter elements of array\n");
- for (int i = 0; i < size; i++)
- {
- scanf("%d", &a[i]);
- }
- for (int i = 0; i < size; i+=2)
- {
- if(a[i]>0)
- {
- int minIndex = i;
- for (int j = i + 2; j < size; j += 2)
- {
- if (a[j] < a[minIndex])
- {
- minIndex = j;
- }
- }
- swap (a[i], a[minIndex]);
- }
- }
- printf("Output array\n");
- for (int i = 1; i < size; i += 2)
- {
- printf("%d ", a[i]);
- }
- system ("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment