Skip to content

Instantly share code, notes, and snippets.

@ustbgaofan
Forked from Embedded-linux/Bubble sort in C
Created September 19, 2013 15:29
Show Gist options
  • Save ustbgaofan/6625218 to your computer and use it in GitHub Desktop.
Save ustbgaofan/6625218 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main()
{
int s,temp,i,j,a[20];
printf("Enter total no. of elements:");
scanf("%d",&s);
printf("Enter %d elements:",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
//Bubble Sort Alogrithm
for(i=s-2;i>=0;i--)
{
for(j=0;j<=i;j++)
{
if (a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("After sorting:\n");
for (i=0;i<s;i++)
printf(" %d ",a[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment