This C program sorts a given array of integer numbers using Bubble Sort technique.

The algorithm gets its name from the way smaller elements “bubble” to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Time Complexity of this algorithm is O(n

The algorithm gets its name from the way smaller elements “bubble” to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Time Complexity of this algorithm is O(n

^{2}).Here is the source code of the C program to sort integers using Bubble Sort technique. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C Program to sort an array using Bubble Sort technique`

`*/`

`#include <stdio.h>`

void bubblesort(int arr[], int size)

`{`

int i, j;

for (i = 0; i < size; i++)

`{`

for (j = 0; j < size - i; j++)

`{`

if (arr[j] > arr[j+1])

swap(&arr[j], &arr[j+1]);

`}`

`}`

`}`

void swap(int *a, int *b)

`{`

int temp;

temp = *a;

*a = *b;

*b = temp;

`}`

int main()

`{`

int array[100], i, size;

printf("How many numbers you want to sort: ");

scanf("%d", &size);

printf("\nEnter %d numbers : ", size);

for (i = 0; i < size; i++)

scanf("%d", &array[i]);

bubblesort(array, size);

printf("\nSorted array is ");

for (i = 0; i < size; i++)

printf(" %d ", array[i]);

return 0;

`}`

$ gcc bubblesort.c -o bubblesort $ ./bubblesort How many numbers you want to sort: 5 Enter 5 numbers : 345 3 20 35 333 Sorted array is : 3 20 35 333 345

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Here’s the list of Best Reference Books in C Programming, Data Structures and Algorithms.