fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define SIZE 10
  5.  
  6. int main(void) {
  7. char towns[SIZE][50] = {"Zayed", "Talkha", "Cairo", "Alexandria",
  8. "Mansoura", "Giza", "Luxor", "Aswan",
  9. "Tanta", "Ismailia"};
  10. char temp[50];
  11.  
  12. // ترتيب الفقاعات (Bubble Sort) للنصوص
  13. for (int i = 0; i < SIZE - 1; i++) {
  14. for (int j = 0; j < SIZE - i - 1; j++) {
  15. if (strcmp(towns[j], towns[j + 1]) > 0) {
  16. strcpy(temp, towns[j]);
  17. strcpy(towns[j], towns[j + 1]);
  18. strcpy(towns[j + 1], temp);
  19. }
  20. }
  21. }
  22.  
  23. printf("Alphabetized list of towns:\n");
  24. for (int i = 0; i < SIZE; i++) {
  25. printf("%s\n", towns[i]);
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Alphabetized list of towns:
Alexandria
Aswan
Cairo
Giza
Ismailia
Luxor
Mansoura
Talkha
Tanta
Zayed