When writing my code, I can get to sort my numbers as long as I list the first number to be the lowest. if I use random numbers like 1, 456,and 12 it will work but when I change them up say to 456,1,and 12 it breaks. Here is part of my code.
insert
Code:
void myfunction(double *a1, double *b1, double *c1)
{ double small, middle, large;
if (*a1 <= *b1)
{
if (*a1 <= *c1)
{
small = *a1;
if (*b1 <= *c1)
{
middle = *b1;
large = *c1; }
else {
middle = *c1;
large = *b1;
} } }
else
myfunction(b1, a1, c1);
*a1 = small;
*b1 = middle;
*c1 = large; }
// Unsorted and sorted numbers
void sortandprint(double a1, double b1, double c1)
{ printf("Static before numbers: %2.lf, %2.lf, %2.lf\n", a1, b1, c1);
myfunction(&a1, &b1, &c1);
printf("Sorted static numbers: %2.lf, %2.lf, %2.lf\n", a1, b1, c1); }
// Print and sort
int main(void)
{ sortandprint(9, 125, 789);
system("PAUSE");
return 0;
}