Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
#include
#include
// Comparing function: // Returns a positive number if a is greater than b // Returns a negative number if a is less than b // Returns 0 if a is equal to b int compare(const void *a, const void *b) { int *valA = a; int *valB = b; return *valA - *valB; } int main() { // Create an array int myArray[] = {20, 32, 5, 2, 24, 15}; int size = sizeof(myArray) / sizeof(myArray[0]); // Sort the values in the array qsort (myArray, size, sizeof(myArray[0]), compare); // Display the values of the array for(int i = 0; i < size; i++) { printf("%d ", myArray[i]); } return 0; }
2 5 15 20 24 32