Write a program segment to sort the given array in alphabeti
Write a program segment to sort the given array in alphabetical order using the bubble sort method.
| Pet[0]= \"dog\" | Pet[1]= \"cat\" | Pet[2]= \"bird\" | 
| Pet[3]= \"snake\" | Pet[4]= \"duck\" | Pet[5]= \"fish\" | 
| Pet[6]= \"rabbit\" | Pet[7]= \"mouse\" | Pet[8]= \"pony\" | 
| Pet[9]= \"frog\" | 
Solution
#include<stdio.h>
 #include <string.h>
 void main(){
 char name[10][8], tname[10][8], temp[8];
 int i, j, n;
 printf(\"Enter the value of n \ \");
 scanf(\"%d\", &n); printf(\"Enter %d names n\", \ );
 for (i = 0; i < n; i++) {
 scanf(\"%s\", name[i]); strcpy(tname[i], name[i]);
 }
 for (i = 0; i < n - 1 ; i++) {
 for (j = i + 1; j < n; j++) {
 if (strcmp(name[i], name[j]) > 0) {
 strcpy(temp, name[i]); strcpy(name[i], name[j]); strcpy(name[j], temp);
 }
 }
 }printf(\"\ ----------------------------------------\ \");
 printf(\"Input NamestSorted names\ \");
 printf(\"------------------------------------------\ \");
 for (i = 0; i < n; i++) {
 printf(\"%s\\t\\t%s\ \", tname[i], name[i]);
 }printf(\"------------------------------------------\ \");
 }
![Write a program segment to sort the given array in alphabetical order using the bubble sort method. Pet[0]= \ Write a program segment to sort the given array in alphabetical order using the bubble sort method. Pet[0]= \](/WebImages/31/write-a-program-segment-to-sort-the-given-array-in-alphabeti-1089943-1761573740-0.webp)
