C program to sort array using bubble sort algorithm

Sorting data either in ascending or descending order is the important computing application that can be achieved by various ways. In this tutorial, we will learn about c program to sort array using bubble sort algorithm.

C program to sort array using bubble sort algorithm

In this method, smaller values gradually move upward or bubble to the top like an air bubble in water and larger values sink down to the bottom of the array.

In every loop, the successive pairs of the elements are compared and swapped if necessary. If the pair has the same value or is in increasing order, we leave as they are.

If there are n elements to be sorted then bubble sorting make n-1 passes through the array.

Let’s see visually how this works.

For better understanding of the program, you should have proper knowledge of following c programming topics :