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. for(int i=0;i<4;i++){
  20. for(int j=0;j<4-i;j++){
  21. if(data[j].height<data[j+1].height)swap(&data[j],&data[j+1]);
  22. }
  23. }
  24. for(int i=0;i<5;i++){
  25. printf("%d, %d, %d\n",data[i].id,data[i].weight,data[i].height);
  26. }
  27. return 0;
  28. }
  29.  
  30. void swap(Body *a,Body *b){
  31. Body t=*a;
  32. *a=*b;
  33. *b=t;
  34. }
  35.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161