20/*Write a’C’Program to accept 5 names from user and store these names into an array.Sort these array elements in alphabeticalorder*/


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int n,i,j;
char list[20][20],temp[20];
printf(“\n How many strings ?”);
scanf(“%d”,&n);
if(n<0)
{
printf(“\n Invalid input”);
}
printf(“\n Enter the %d strings \n”,n);
for(i=0;i<n;i++)
{
fflush(stdin);
gets(list[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(list[i],list[j])>0)
{
strcpy(temp,list[i]);
strcpy(list[i],list[j]);
strcpy(list[j],temp);
}
}
}
printf(“\n The sorted list is:\n”);
for(i=0;i<n;i++)
puts(list[i]);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s