/* Program to sort list of names in alphabetical order */ /* Problem 21 */ #include #include #include main() { char names[20][20]; char temp[20]; int n,i,j; clrscr(); printf("Please enter the number of names you will enter : "); scanf("%d",&n); printf("\nNow enter those names (separated by or ) : "); printf("\n\n"); for (i = 0; i < n; i++) scanf("%s",names[i]); for (i = 0; i < n; i++) { for (j = i; j < n; j++) { if (strcmp(names[i],names[j]) > 0) { strcpy(temp,names[i]); strcpy(names[i],names[j]); strcpy(names[j],temp); } } } printf("\nThe alphabetically ordered list is as follows : "); printf("\n"); for (i = 0; i < n; i++) printf("\n%-10s",names[i]); printf("\n\nPress any key to exit..."); getch(); }