Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- char array[10][10], temp[10];
- int i,j,n;
- printf("How many strings?: ");
- scanf("%d",&n);
- printf("Enter %d strings.\n",n);
- for(i=0;i<n;i++)
- scanf("%s",array[i]);
- for(i=0; i<(n-1); i++)
- {
- for(j=0;j<(n-i-1);j++)
- {
- if(strcmp(array[j],array[j+1])>0)
- {
- strcpy(temp,array[j]);
- strcpy(array[j],array[j+1]);
- strcpy(array[j+1],temp);
- }
- }
- }
- printf("Strings after sorting is:-\n");
- for(i=0;i<n;i++)
- printf("%s\n",array[i]);
- }
- //Output
- //How many strings?: 3
- //Enter 3 strings.
- //Ham
- //Eggs
- //Beef
- //Strings after sorting is:-
- //Beef
- //Eggs
- //Ham
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement