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 .
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 : :
Output :
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 .
need an explanation for this answer? contact us directly to get an explanation for this answer