C program that would sort a list of names in alphabetical order

#define N 5
#define MAX 20 
void main()
char string[N][MAX], temp[MAX];
int i=0, j=0;
printf(“enter names of %d items”, N); 
scanf(“%s”, string[i++]); 
for(i=1; i<N; i++)
for(j=1; j<=N-i; j++)
if(strcmp(string[j-1], string[j])>0)
strcpy(temp, string[j-1]); 
strcpy(string[j-1], string[j]);
strcpy(string[j], temp);
printf(“alphabetical list”); 
for(i=0; i<N; i++) 
printf(“%s”, string[i]);

enter names of 5 times

renuka rama krishna ravi divya

alphabetical list

divya  krishna rama ravi renuka 

Leave a Reply