Hey! plz send me code for this Take 5 country names in an array as input and create a function which will sort that country names in alphabetical order.
Code: #include <stdio.h> #include <string.h> #define countryNo 5 #define maxLength 100 void sortNames(char country[countryNo][maxLength]) { char temp[maxLength]; int i, j; // [URL=http://www.go4expert.com/articles/bubble-sort-algorithm-absolute-beginners-t27883/]bubble sort[/URL] for (j = 0; j < countryNo - 1; j++) { for (i = 0; i < countryNo - 1; i++) { if (strcmp(country[i], country[i + 1]) > 0) { strcpy(temp, country[i]); strcpy(country[i], country[i + 1]); strcpy(country[i + 1], temp); } } } } int main(int argc, char **argv) { char country[countryNo][maxLength]; int i; // enter names for (i = 0; i < countryNo; i++) { printf("Enter name of country #%d: ", i + 1); gets(country[i]); } sortNames(country); // display for (i = 0; i < countryNo; i++) { printf("%s\n", country[i]); } return 0; }