Code:
#include stdio.h
#include conio.h
#include string.h
void main()
{
clrscr();
char str[5][20], t[20];
int i, j;
printf("Enter any five string (name) : ");
for(i=0; i<5 font="" i="">5>
{
scanf("%s",str[i]);
}
for(i=1; i<5 font="" i="">5>
{
for(j=1; j<5 font="" j="">5>
{
if(strcmp(str[j-1], str[j])>0)
{
strcpy(t, str[j-1]);
strcpy(str[j-1], str[j]);
strcpy(str[j], t);
}
}
}
printf("Strings (Names) in alphabetical order : \n");
for(i=0; i<5 font="" i="">5>
{
printf("%s\n",str[i]);
}
getch();
}
Output:
Execute and get the output.
More C Programs: