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