Bubble sort

Program to implement bubble sorting on a string.


#include<stdio.h>
#include<conio.h>
main()
{
int i,j,n,a[10],temp;
clrscr();
printf("\nEnter the no of elements : ");
scanf("%d",&n);
printf("\nEnter the elements \n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Sorting array.... " );
getch();
for(i=0;i<n-1;i++)
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
printf("\nSorted array is \n");
for(i=0;i<n;i++)
printf("\n%d",a[i]);
getch();
return 0;
}

Category:

0 comments: