sorting function
1. The method
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TOTAL 9
int main()
{
int i, j,size, seed;
double numbers[TOTAL], temp;
seed = time(NULL);
srand(seed);
printf("The random numbers are:\n");
for(i=0; i<TOTAL;i++)
{
numbers[i] = (double) rand()/(double) RAND_MAX;
printf(" %1f\n",numbers[i]);
}
for (size = TOTAL-1 ; size >= 0; size--)
{
for(j=0; j<=size-1; j++)
{
if (numbers[j] > numbers[j+1])
{
temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
}
}
}
printf("These numbers, sorted are:\n");
for(i=0; i<TOTAL;i++)
{
printf("%1f\n",numbers[i]);
}
return 0;
}