Below is the C program to implement bubble sort algorithm. The code output the number of swaps taken and the sorted array. In the code the average case input and worst case input has been commented out, therefore this code will take as input the worst case input.

Worst case input is a reverse sorted array and best case input is a sorted array.

The input is in array *a* and the algorithm sorts the input in the array given. Hence space complexity is O(1).

**Output:** Number of swaps, followed by sorted array in the next line.

**Time Complexity:** Worst Case time complexity is O(n^{2}) in case of reverse sorted array and best Case time complexity is O(n) in case of already sorted array.

**Compiler Used**: GCC