one trick I have used is to use a second array of integers that contain the index values in the array you want to sort. When its time to swap elements, swap the integers in this second array, which keeps the original array in its original order.
In the code below you should use const int to represent array sizes, not hard-code them like I did.
Code:
double a[8];
int i,j;
int index[8] = {0,1,2,3,4,5,6,7};
// simple bubble-sort algorithm
for( i = 0; i < 6; i++)
{
for( j = i+1; j < 7; j++)
{
if( a[index[i]] > a[index[j]])
{
int t = index[i];
index[i] = index[j];
index[j] = t;
}
}
}
// now list the array in sorted order
for(i = 0; i < 7; i++)
printf("%f ", a[index[i]]);