I want to sort this in ascending order
double x[]={2.5, 1.5, 4.0, 7.0, 3.5, 6.5, 8.5, 1.0};
I know I screwed it all up, but here is what I have so far:
I guess what I was trying to do was set the first value of the array to the lowest number in the array and continue that process until they were all in order. But I messed up somewhere. Btw, I only know very basic C commands.
double x[]={2.5, 1.5, 4.0, 7.0, 3.5, 6.5, 8.5, 1.0};
I know I screwed it all up, but here is what I have so far:
Code:
#include <stdio.h>
int main(void)
{
int k, j, m, npts=8;
double hold;
double x[]={2.5, 1.5, 4.0, 7.0, 3.5, 6.5, 8.5, 1.0};
for (k=0; k<=npts-2; k++)
{
m = k;
for (j=k+1; j<=npts-1; j++)
if (x[j] < x[m])
m = j;
hold = x[m];
x[m] = x[k];
x[k] = hold;
}
return;
}
I guess what I was trying to do was set the first value of the array to the lowest number in the array and continue that process until they were all in order. But I messed up somewhere. Btw, I only know very basic C commands.