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