Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C Compiler.
- Code, Compile, Run and Debug C program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <stdio.h>
- #define SIZE 10
- int main()
- {
- int i,j, temp,arr[SIZE]={2,7,8,1,4,3,6,9,10,5};
- printf("ARRAY BEFORE SORTING:\n");
- for(i=0;i<SIZE;i++)//print an array
- printf("%d\t",arr[i]);
- printf("\n");
- for(i=0;i<SIZE;i+=2)//sort array of elements i = 0, 2, 4, 6, 8
- {
- for(j=i+2;j<SIZE;j+=2)
- {
- if(arr[i]<arr[j])//noneven
- {
- temp = arr[i];
- arr[i] = arr[j];
- arr[j]= temp;
- }
- }
- }
- for(i=1;i<SIZE;i+=2)//sort array of elements i=1, 3, 5, 7
- {
- for(j=i+2;j<SIZE;j+=2)
- {
- if(arr[i]>arr[j])//noneven
- {
- temp = arr[i];
- arr[i] = arr[j];
- arr[j]= temp;
- }
- }
- }
- printf("ARRAY AFTER SORTING:\n");
- for(i=0;i<SIZE;i++)//print an array
- printf("%d\t",arr[i]);
- printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement