c8-27-1.c 573 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {void sort(char *name[ ],int n);
  5. void print(char *name[ ],int n);
  6. char *name[ ]={"Follow me","BASIC","Great Wall","FORTRAN","Computer design"};
  7. int n=5;
  8. sort(name,n);
  9. print(name,n);
  10. return 0;
  11. }
  12. void sort(char *name[ ],int n)
  13. {char *temp;
  14. int i,j,k;
  15. for(i=0;i<n-1;i++)
  16. {k=i;
  17. for(j=i+1;j<n;j++)
  18. if(strcmp(name[k],name[j])>0) k=j;
  19. if(k!=i)
  20. {temp=name[i]; name[i]=name[k]; name[k]=temp;}
  21. }
  22. }
  23. void print(char *name[ ],int n)
  24. {int i;
  25. for(i=0;i<n;i++)
  26. printf("%s\n",name[i]);
  27. }