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