sort algorithm in c code example
Example 1: sorting program in c
#include
int main(){
/* Here i & j for loop counters, temp for swapping,
* count for total number of elements, number[] to
* store the input numbers in array. You can increase
* or decrease the size of number array as per requirement
*/
int i, j, count, temp, number[25];
printf("How many numbers u are going to enter?: ");
scanf("%d",&count);
printf("Enter %d elements: ", count);
// Loop to get the elements stored in array
for(i=0;inumber[j]){
temp=number[i];
number[i]=number[j];
number[j]=temp;
}
}
}
printf("Sorted elements: ");
for(i=0;i
Example 2: using sort function in c
void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))