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 *a, Body *b);
  10.  
  11. int main(void) {
  12. Body data[] = {
  13. {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<4;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<5;i++){
  29. printf("%d, %d, %d\n",
  30. data[i].id,
  31. data[i].weight,
  32. data[i].height);
  33. }
  34.  
  35. return 0;
  36. }
  37.  
  38. void swap(Body *a, Body *b){
  39. Body temp=*a;
  40. *a=*b;
  41. *b=temp;
  42. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161