SORT LIST OF NAMES IN ALPHABETICAL ORDER
C Program to sort the list of names of persons in alphabetical order using Bubble sort technique
#include<stdio.h>#include<string.h>
void main(void)
{
int i,k,n;
char*name[50],*temp="";
printf("\nEnter number of persons:");
scanf("%d",&n);
for(i=0;i<n;i++) gets(name[i]);
for(k=0;k<(n-1);k++)
{
for(i=0;i<(n-k-1);i++)
{
if(strcmp(name[i],name[i+1]>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[i+1]);
strcpy(name[i+1],temp);
}
}
}
printf("\nSorted List....\n");
for(i=0;i<n;++i)
puts(name[i]);
}
Comments
Post a Comment