C PROGRAMMINGDATA STRUCTURES

write a c program to implement bubble sort on an array

Bubble sort 

  #include <stdio.h>
main()
{
int a[100], number, i, j, temp;

printf("n Please Enter the total Number of Elements : ");
scanf("%d", &number);

printf("n Please Enter the Array Elements : ");
for(i = 0; i < number; i++)
scanf("%d", &a[i]);

for(i = 0; i < number - 1; i++)
{
for(j = 0; j < number - i - 1; j++)
{
if(a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
printf("n List Sorted in Ascending Order : ");
for(i = 0; i < number; i++)
{
printf(" %d t", a[i]);
}
printf("n");
getch();
}
Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button