#include(iostream.h)
#include(conio.h)
#include(stdio.h)
#include(string.h)
void main()
{
char st[10][10],temp[10];
int i, j, n;
clrscr();
cout<<"Enter the no. of names:";
cin>>n;
cout<<"Enter the different names:";
for(i=0; i< n; i++)
cin>>st[i];
for(i=0; i< n; i++)
{
for(j=i; j< n-1; j++)
{
if(strcmp(st[i], st[j+1]) >0)
{
strcpy(temp,st[i]);
strcpy(st[i],st[j+1]);
strcpy(st[j+1],temp);
}
}
}
cout<<"Given names after ascending order:";
for(i=0;i<5;i++)
cout<< st[i];
getch();
}
Output: Enter the no.of names: 5
Enter the different names: apple
cat
boy
apec
suresh
Given names after ascending order:
apec
apple
boy
cat
suresh
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Monday, March 2, 2009
Subscribe to:
Post Comments (Atom)
Thaannnxxxxxx
ReplyDeletei m not satisfied with this program
ReplyDeleteHow do u sort n names. Should we use 2d arrays. Please help
ReplyDeleteHow do you sort n names should we use 2d array???
ReplyDeletehow do you sort names using a 2d array???
ReplyDeletewhat of two names like the first name and second name
ReplyDeleteThanks 😊 sir
ReplyDeleteIt's better to write comments for every line
ReplyDeletenice website development
ReplyDelete