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