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