Using selection sort for C
How can I use selection sort for my array, sorting it and then printing it out from highest to lowest.
int grade[10] = {10, 18, 22, 15, 9, 0, 15, 18, 76, 58};
Example for what is printed to screen:
Something like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void Sort(int array[], int arrayLength)
{
for(int i = 0; i < arrayLength; i++)
{
for(int j = i+ 1; j < arrayLength; j++)
{
if(array[j] < array[i])
{
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
|
Thanks. Just one more thing. How would I incorporate my above array so that it prints out in descending order?
Same thing just change
to
Topic archived. No new replies allowed.