Â
In this, we are going to see a program in which we will sort a set of strings in alphabetical order in C Programming Language.
//Program to sort set of strings in alphabetical order
#include <stdio.h>
#include <string.h>
void main()
{
char s[5][20], t[20];
int i, j;
printf("Enter any five strings:\n");
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("Strings in alphabetical order are: ");
for (i = 0; i < 5; i++)
{
printf("\n%s", s[i]);
}
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP