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