- WAP to sort an array Using BUBBLE sort(Ascending Order).
#include <conio.h>
void main()
{
int a[10],i,j;
printf("Enter the array element");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
//Ascending Order
if(a[i]>a[j])
a[i]=(a[i]+a[j])-(a[j]=a[i]); // one line swapping.
}
}
printf("The sorted array is:");
for(i=0;i<10;i++)
printf("%d ",a[i]);
}
No comments:
Post a Comment