Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void reorder(int n, char *x[]);
- int main()
- {
- char *country_names[] = {"India", "Russia", "Brazil", "China", "South Africa", "Nigeria"};
- int n = sizeof(country_names)/sizeof(country_names[0]);
- printf("List of country names before sorting:\n");
- for(int i = 0; i < n; i++)
- printf("%s\n", country_names[i]);
- reorder(n, country_names);
- printf("\nList of country names after sorting:\n");
- for(int i = 0; i < n; i++)
- printf("%s\n", country_names[i]);
- return 0;
- }
- void reorder(int n, char *x[])
- {
- int i, j;
- char temp[50];
- for(i = 0; i < n-1; i++)
- {
- for(j = i+1; j < n; j++)
- {
- if(strcmp(x[i], x[j]) > 0)
- {
- strcpy(temp, x[i]);
- strcpy(x[i], x[j]);
- strcpy(x[j], temp);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement