In this program, the user is ask to enter the several strings, then the given strings will be sorted lexicographically. With strings, the usual order is Lexicographic Order. This is dictionary order, except that all the uppercase letters precede all the lowercase letters. ... Two strings are lexicographically equal if they are the same length and contain the same characters in the same positions. For example, you have a strings as HTML, C, PHP then the sorted order is C, HTML, PHP.
#include<stdio.h>
#include<string.h>
void main()
{
int i, j;
char temp[30];
char str[10][30];
printf("Enter any 10 words\n");
for(i=0; i<10; i++)
{
gets(str[i]);
}
for(i=0; i<10; i++)
{
for(j=0; j<10; j++)
{
if(strcmp(str[j], str[j+1]) > 0)
{
strcpy(temp, str[j]);
strcpy(str[j], str[j+1]);
strcpy(str[j+1], temp);
}
}
}
printf("\nSorted words are..\n");
for(i=0; i<10; i++)
{
printf("%s\n", str[i]);
}
getch();
}
Enter any 10 words
C
C++
Java
PHP
Perl
Html
VB
JSP
Python
Android
Sorted words are..
Android
C
C++
Html
JSP
Java
PHP
Perl
Python
VB