#include <stdio.h>
int main()
{
int arr[30];
int i, j, k, tmp, num;
printf("Enter total no. of elements : ");
scanf("%d", &num);
for (k = 0; k < num; k++)
{
printf("\nEnter %d number : ", k + 1);
scanf("%d", &arr[k]);
}
for (i = num / 2; i > 0; i = i / 2)
{
for (j = i; j < num; j++)
{
for (k = j - i; k >= 0; k = k - i)
{
if (arr[k + i] >= arr[k])
break;
else
{
tmp = arr[k];
arr[k] = arr[k + i];
arr[k + i] = tmp;
}
}
}
}
printf("\nShell Sorting : ");
for (k = 0; k < num; k++)
{
printf("%d\t", arr[k]);
}
return 0;
}
Output:-
Enter total no. of elements : 5
Enter 1 number : 4
Enter 2 number : 6
Enter 3 number : 1
Enter 4 number : 5
Enter 5 number : 3
Shell Sorting : 1 3 4 5 6
Post a Comment
If you have any doubts, Please let me know
Thanks!