#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,k,x,a[100],n,temp,pos;
printf("Enter the number of elements in your array: \n\n");
scanf("%d",&n);
printf("Now, enter the elements of the array that you want to sort: \n\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Here is the UNSORTED ARRAY:\n\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
if(a[j]>a[i])
{
temp=a[i];
a[i]=a[j];
for(k=i;k>j;k--)
{
a[k]=a[k-1];
}
a[k+1]=temp;
}
}
printf("\n\nThe array after step %d -- ",i+1);
for(x=0;x<n;x++)
{
printf("%d ",a[x]);
}
}
getch();
return 0;
}
No comments:
Post a Comment