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