#include <stdio.h>
main()
{
int arr[100],i,j,n,temp;
printf("Enter the number of elements : ");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Unsorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
for(j=1;j<n;j++)
{
temp=arr[j];
for(i=j-1;i>=0 && temp<arr[i];i--)
arr[i+1]=arr[i];
arr[i+1]=temp;
}
printf("Sorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
main()
{
int arr[100],i,j,n,temp;
printf("Enter the number of elements : ");
scanf("%d",&n);
for (i = 0; i < n; i++)
{
printf("Enter element %d : ",i+1);
scanf("%d", &arr[i]);
}
printf("Unsorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
for(j=1;j<n;j++)
{
temp=arr[j];
for(i=j-1;i>=0 && temp<arr[i];i--)
arr[i+1]=arr[i];
arr[i+1]=temp;
}
printf("Sorted list is :\n");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
}
No comments:
Post a Comment