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