C Programming Code Examples C > Sorting Searching Code Examples C Program to Sort Elements in Lexicographical Order (Dictionary Order) C Program to Sort Elements in Lexicographical Order (Dictionary Order) This program takes 10 words(strings) from the user and sorts them in lexicographical order. #include<stdio.h> #include <string.h> int main() { int x, j; char str[10][80], temp[80]; printf("Enter 10 words:\n"); for(x=0; x<10; ++x) scanf("%s[^\n]",str[x]); for(x=0; x<9; ++x) for(j=x+1; j<10 ; ++j) { if(strcmp(str[x], str[j])>0) { strcpy(temp, str[x]); strcpy(str[x], str[j]); strcpy(str[j], temp); } } printf("\nIn lexicographical order: \n"); for(x=0; x<10; ++x) { puts(str[x]); } return 0; }