I would like to sort an array of floats using bubble sort in C. I would like this function to return this sorted array, and be assigned to my variable testSorted. However, when I print testSorted the output is 0.0000. Can anyone please help out here?
float * bubbleSort(float statsArray[], int n){
float swap;
for ( int a = 0; a < n-1; a++)
{
for (int b = 0; b < n - a - 1; b++)
{
if (statsArray[b] < statsArray[b+1])
{
swap = statsArray[b];
statsArray[b] = statsArray[b+1];
statsArray[b+1] = swap;
}
}
}
return statsArray;
}
void main() {
float test[SIZE] = { 34, 201, 190, 154, 8, 194, 2, 6,
114, 88, 45, 76, 123, 87, 25, 23,
200, 122, 150, 90, 92, 87, 177, 244,
201, 6, 12, 60, 8, 2, 5, 67,
7, 87, 250, 230, 99, 3, 100, 90};
/* Variable Declarations */
float average;
float * testSorted;
int p;
float maximum, minimum;
p = 40;
testSorted = bubbleSort(test, p);
printf(testSorted);
return 0;
}
printf(float_array). You should consider writing a loop to print the elements individually with%fplaceholder in the format