Sort strings in Alphabetical order
Write a C Program to Sort strings in Alphabetical order. Here’s simple C Program to Sort strings in Alphabetical order in C Programming Language.
Below is the source code for C Program to Sort strings in Alphabetical order which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C Program to Sort string in Alphabetical order */ #include<stdio.h> #include<string.h> void main() { char s[5][20], t[20]; int i, j; clrscr(); printf("\nEnter any five strings : "); for (i = 0; i < 5; i++) scanf("%s", s[i]); for (i = 1; i < 5; i++) { for (j = 1; j < 5; j++) { if (strcmp(s[j - 1], s[j]) > 0) { strcpy(t, s[j - 1]); strcpy(s[j - 1], s[j]); strcpy(s[j], t); } } } printf("\nStrings in order are : "); for (i = 0; i < 5; i++) printf("\n%s", s[i]); getch(); }
Output :
/* C Program to Sort strings in Alphabetical order */ Enter any five strings : abq abw aba abc abi Strings in order are : aba abc abi abq abw
Above is the source code for C Program to Sort string in Alphabetical order which is successfully compiled and run on Windows System.The Output of the program is shown above .
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post….