Skip to content

Instantly share code, notes, and snippets.

@Kinjalrk2k
Created April 13, 2019 11:50
Show Gist options
  • Save Kinjalrk2k/beff3354b0ce981e0807a81f068ad997 to your computer and use it in GitHub Desktop.
Save Kinjalrk2k/beff3354b0ce981e0807a81f068ad997 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include <string.h>
int main()
{
int i, j, n;
char str[100][50], temp[50];
printf("Enter the no. of words");
scanf("%d", &n);
printf("Enter the words:\n");
for(i=0; i<n; i++)
scanf("%s[^\n]",str[i]);
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n ; j++)
{
if(strcmp(str[i], str[j])>0)
{
strcpy(temp, str[i]);
strcpy(str[i], str[j]);
strcpy(str[j], temp);
}
}
}
printf("\nIn lexicographical order: \n");
for(i=0; i<n; ++i)
puts(str[i]);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment