Skip to content

Instantly share code, notes, and snippets.

@78526Nasir
Created February 17, 2016 13:15
Show Gist options
  • Save 78526Nasir/6aba35e87e2434259944 to your computer and use it in GitHub Desktop.
Save 78526Nasir/6aba35e87e2434259944 to your computer and use it in GitHub Desktop.
Bubble Sort Implementation In C using Array !
/// Bubble sort ///
#include<stdio.h>
main()
{
int a[100],i,p,n,temp;
printf("Enter how many elements for your Array:");
scanf("%d",&n);
printf("\nEnter %d values :",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nAscending to Descending ");
for(p=0;p<n-1;p++)
{
for(i=0;i<n-1-p;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf("\n\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment