Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created May 18, 2014 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimitoboku/76bb45a1ba7ca50c276e to your computer and use it in GitHub Desktop.
Save kimitoboku/76bb45a1ba7ca50c276e to your computer and use it in GitHub Desktop.
bubblesort
#include<stdio.h>
void bubblesort(int array[],int n){
int i;
for(i=n-1;i!=0;i--){
int index;
for(index = 0; index < i ;index++){
if(array[index] > array[index+1]){
int n = array[index];
array[index] = array[index+1];
array[index+1] = n;
}
}
}
}
int main(void){
int array[100];
int n;
scanf("%d",&n);
int i;
for(i=0;i<n;i++){
scanf("%d",&array[i]);
}
bubblesort(array,n);
for(i=0;i<n;i++){
printf("%d ",array[i]);
}
puts("");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment