C Programming Code Examples C > Sorting Searching Code Examples Program to Sort the Array Elements using Gnome Sort Program to Sort the Array Elements using Gnome Sort This C Program sort the array elements using gnome sort. Gnome sort(stupid sort) is a sorting algorithm which is similar to insertion sort, except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort. It is conceptually simple, requiring no nested loops. #include <stdio.h> void main() { int j, temp, ar[10], n; printf("\nenter the elemts number u would like to enter:"); scanf("%d", &n); printf("\nenter the elements to be sorted through gnome sort:\n"); for (j = 0; j < n; j++) scanf("%d", &ar[j]); j = 0; while (j < n) { if (j == 0 || ar[j - 1] <= ar[j]) j++; else { temp = ar[j-1]; ar[j - 1] = ar[j]; ar[j] = temp; j = j - 1; } } for (j = 0;j < n;j++) printf("%d\t", ar[j]); }