BUBBLE SORTING
Posted by JanWan
Last Updated: March 03, 2012
#include <stdio.h>
#include <conio.h>

int main(void)
{
int item[100];
int a, b, t;
int count;
/* Welcome */
printf("***************************************************\n"
        "############ WELCOME TO BUBBLE SORTING ############\n"
    "***************************************************\n");
/*Read in number*/
printf("\nHow many numbers?");
scanf("%d", &count);
for(a = 0; a < count; a++)
scanf("%d", &item[a]);
/*Now, sort the number using bubble sort*/
for(a = 1; a < count; a++)
for(b = count - 1; b >= a; b--)
{
/* Compare adjacent elements */
if(item[b - 1] > item[b])
{
/* Exchange elements */
t = item[b - 1];
item[b - 1] = item[b];
item[b] = t;
}
}
/* Display sorted list */
printf("\nList Sorted In Assending Order");
for(t = 0; t < count; t++)
printf("\n%d\n", item[t]);
return 0;
}
Related Content