VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-to-sort-an-array-in-ascending-order/

⇱ C Program to Sort an Array in Ascending Order - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program to Sort an Array in Ascending Order

Last Updated : 12 Jul, 2025

Sorting an array in ascending order means arranging the elements in the order from smallest element to largest element.

The easiest way to sort an array in C is by using qsort() function. This function needs a comparator to know how to compare the values of the array. Let's look at a simple example:


Output
1 2 3 4 5 6 

Explanation: The comp() function is the comparator that returns difference between the first and second element, otherwise returns 0 or negative value. This will sort the array in ascending order.

C language only provides the built-in implementation of quicksort algorithm. If you want to use other sorting algorithm apart from quicksort, you have to manually implement it.

Using Selection Sort

Selection sort is a simple sorting algorithm that repeatedly finds the minimum element from the unsorted part of the array and places it at its position in the sorted part of the array until the complete array is sorted.


Output
1 2 3 4 5 6 

Using Bubble Sort

In Bubble Sort Algorithm, we repeatedly swap adjacent elements if they are in the wrong order. This process is repeated until the array is sorted.


Output
1 2 3 4 5 6 
Comment
Article Tags: