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