fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct {
  4. int id;
  5. int weight;
  6. int height;
  7. }Body;
  8. int swap(Body member[]);
  9. int main(void) {
  10. Body a[]={{1,65,169},{2,73,170},{3,59,161},{4,79,175},{5,55,168}};
  11. swap(a);
  12. for(int i=4;i>=0;i--){
  13. printf("%d,%d,%d\n",a[i].id,a[i].weight,a[i].height);
  14. }
  15. return 0;
  16. }
  17.  
  18. int swap(Body member[]){
  19. Body top[]={0};
  20. for(int i=0;i<5;i++){
  21. for(int j=i+1;j<5;j++){
  22. if(member[i].height>member[j].height){
  23. top[i]=member[i];
  24. member[i]=member[j];
  25. member[j]=top[i];
  26. }
  27. }
  28. }
  29. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
4,79,175
2,73,170
1,65,169
5,55,168
3,59,161