A program of bubble sort in ascending order

/* A program of bubble sort in ascending order */

#include

int main(void)
{
int i,j,n,array[50],tem;

printf(“Enter how many number are you want to sort , maximum size is 50 :\n”);
scanf(“%d”,&n);

printf(“Now Enter %d numbers :\n”,n);
for(i=0;i
scanf(“%d”,&array[i]);

for(i=1;i<=n-1;i++)
{
for(j=0;j<n-i;j++)

{

if(array[j]>array[j+1e])
{
tem=array[j];
array[j]=array[j+1];
array[j+1]=tem;

}
}
}
printf(“The sorted number are :\n”);
for(i=0;i<n;i++)
printf(“%3d”,array[i]);

return 0;
}

Advertisements
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: