Monday 13 November 2017

C Program to Sort the N Names in an Alphabetical Order


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="">
{
scanf("%s",str[i]);
}
for(i=1; i<5 font="" i="">
{
for(j=1; j<5 font="" j="">
{
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="">
{
printf("%s\n",str[i]);
}
getch();
}


Output:

Execute and get the output.


More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...