Created
April 13, 2019 11:50
-
-
Save Kinjalrk2k/beff3354b0ce981e0807a81f068ad997 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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