131. Program to arrange array in ascending order using bubble sort.
#include<stdio.h>
int
a[5]={1,20,5,12,3},ele,i,t,j;
void
main()
{
ele=sizeof(a)/sizeof(a[0]);
printf("\n");
for(i=0;i<ele;i++)
printf("%d ",*(a+i));
for(i=0;i<ele-1;i++)
{
for(j=0;j<ele-1-i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\n");
for(i=0;i<ele;i++)
printf("%d ",*(a+i));
printf("\n");
}
Comments
Post a Comment