#include<stdio.h>
void main()
{
int a[10]={1,8,6,0,6,68,44,66,45,38};
int i,temp,k,n=10,pos;
for(i=1;i<n;i++)
{
k=i-1;
while(k>=0&&a[k]>a[k+1])
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
k--;
}
}
printf("sorted array\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
output
sorted array
0 1 6 6 8 38 44 45 66 68
void main()
{
int a[10]={1,8,6,0,6,68,44,66,45,38};
int i,temp,k,n=10,pos;
for(i=1;i<n;i++)
{
k=i-1;
while(k>=0&&a[k]>a[k+1])
{
temp=a[k];
a[k]=a[k+1];
a[k+1]=temp;
k--;
}
}
printf("sorted array\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
output
sorted array
0 1 6 6 8 38 44 45 66 68
No comments:
Post a Comment