Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void sort(int array[], const int LENGTH)
- {
- for (int i=0; i<LENGTH; i++)
- for (int j=0; j<LENGTH-1; j++)
- {
- if (array[j]>array[j+1])
- {
- int temp=array[j];
- array[j]=array[j+1];
- array[j+1]=temp;
- }
- }
- return;
- }
- int main()
- {
- int data[]= {9,8,7,10};
- const int LENGTH=4;
- sort(data, LENGTH);
- for (int i=0; i<LENGTH; i++)
- printf("%d %d\n",i, data[i]);
- if (LENGTH%2) // length is odd
- printf("%d\n", data[LENGTH/2]);
- else // length is even - take average of middle two
- printf("%f\n", (data[LENGTH/2-1]+data[LENGTH/2])/2.0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment