C program to implement bubble sort

#include<stdio.h>

int main()
{
int temp,data[8]={10,13,14,21,54,12,20,65},pass=1,k=0;

printf(“Before sorting we had\n”);
for(k=0;k<8;k++)
printf(” %d”,data[k]);

for(pass=1;pass<8;pass++)
{
for(k=0;k<(8-pass);k++)
{
if(data[k]>data[k+1])
{
temp=data[k];
data[k]=data[k+1];
data[k+1]=temp;
}
}
}
printf(“\nAfter sorting in ascending order we have\n”);
for(k=0;k<8;k++)
printf(” %d”,data[k]);
return 0;
}

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>