Skip to content

Instantly share code, notes, and snippets.

@olupotd
Created December 5, 2013 14:36
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 olupotd/7806043 to your computer and use it in GitHub Desktop.
Save olupotd/7806043 to your computer and use it in GitHub Desktop.
Bubble Sort in C
#include<stdio.h>
int numb[8];
int i, j, temp;
int main(int argc, char* argv[])
{
//populate the array
while(i < sizeof(numb)){
numb[i] = i+2;
i++;
}
//sort the array with bubble sort
for(i=0;i<=5;i++)
{
for(j=i+1;j<=sizeof(numb);j++)
{
int temp;
if(numb[i] > numb[j])
{
temp = numb[i];
numb[i] = numb[j];
numb[j] = temp;
}
}
}
//print the results after the sorting
for(i=0;i<=sizeof(numb);i++)
{
printf("%d\n", numb[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment