This C Program sorts the numbers in ascending order using bubble sort. Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. Here we need to sort a number in ascending order.

Here is source code of the C program to sort the numbers in ascending order using bubble sort. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`/*`

`* C program to sort N numbers in ascending order using Bubble sort`

`* and print both the given and the sorted array`

`*/`

`#include <stdio.h>`

`#define MAXSIZE 10`

void main()

`{`

int array[MAXSIZE];

int i, j, num, temp;

printf("Enter the value of num \n");

scanf("%d", &num);

printf("Enter the elements one by one \n");

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

`{`

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

`}`

printf("Input array is \n");

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

`{`

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

`}`

`/* Bubble sorting begins */`

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

`{`

for (j = 0; j < (num - i - 1); j++)

`{`

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

`{`

temp = array[j];

array[j] = array[j + 1];

array[j + 1] = temp;

`}`

`}`

`}`

printf("Sorted array is...\n");

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

`{`

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

`}`

`}`

$ cc pgm21.c $ a.out Enter the value of num 6 Enter the elements one by one 23 45 67 89 12 34 Input array is 23 45 67 89 12 34 Sorted array is... 12 23 34 45 67 89

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

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

If you wish to look at other example programs on Arrays, go to C Programming Examples on Arrays. If you wish to look at programming examples on all topics, go to C Programming Examples.