#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;
printf("Array before sort");
for(i=0;i<n;i++){
printf("%d ",a[i]);
}
for(i=0;i<n;i++)
{
pos=i;
for(k=i+1;k<n;k++)
{
if(a[pos]>a[k])
{
pos=k;
}
}
if(pos!=i)
{
temp=a[pos];
a[pos]=a[i];
a[i]=temp;
}
}
printf("Array after sorting\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
output
Array before sort
1 8 6 0 6 68 44 66 45 38
Array after sort
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;
printf("Array before sort");
for(i=0;i<n;i++){
printf("%d ",a[i]);
}
for(i=0;i<n;i++)
{
pos=i;
for(k=i+1;k<n;k++)
{
if(a[pos]>a[k])
{
pos=k;
}
}
if(pos!=i)
{
temp=a[pos];
a[pos]=a[i];
a[i]=temp;
}
}
printf("Array after sorting\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
output
Array before sort
1 8 6 0 6 68 44 66 45 38
Array after sort
0 1 6 6 8 38 44 45 66 68
No comments:
Post a Comment