#include<stdio.h>
#include<string.h>
void main()
{
int i,j;
//list of names to be sort, you can customize to take input from keyboard
char *list[]={"aj","su","punit","pushp"},*s;
printf("Input List is :")
for(i=0;i<4;i++)
{
printf("\n%s ",*(list+i));
}
for(i=0;i<4;i++)
{
for(j=0;j<4-i-1;j++)
{
if(strcmp(*(list+j),*(list+j+1))>0)
{
s=*(list+j);
*(list+j)=*(list+j+1);
*(list+j+1)=s;
}
}
}
printf("\nSorted List is:\t");
for(i=0;i<4;i++)
{
printf(" %s",*(list+i));
}
}
output
Input List is:
aj
su
punit
pushp
Sorted List is: aj punit pushp su
#include<string.h>
void main()
{
int i,j;
//list of names to be sort, you can customize to take input from keyboard
char *list[]={"aj","su","punit","pushp"},*s;
printf("Input List is :")
for(i=0;i<4;i++)
{
printf("\n%s ",*(list+i));
}
for(i=0;i<4;i++)
{
for(j=0;j<4-i-1;j++)
{
if(strcmp(*(list+j),*(list+j+1))>0)
{
s=*(list+j);
*(list+j)=*(list+j+1);
*(list+j+1)=s;
}
}
}
printf("\nSorted List is:\t");
for(i=0;i<4;i++)
{
printf(" %s",*(list+i));
}
}
output
Input List is:
aj
su
punit
pushp
Sorted List is: aj punit pushp su
No comments:
Post a Comment