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() {
  16.  
  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. for (int i = 0; i < 4; i++) {
  26. for (int j = 0; j < 4-i; j++) {
  27. if (a[j].height < a[j + 1].height) {
  28. swap(&a[j], &a[j + 1]);
  29. }}}
  30.  
  31.  
  32. for (int i = 0; i < 5; i++) {
  33. printf("%d, %d, %d\n", a[i].id, a[i].weight, a[i].height);
  34. }
  35.  
  36. return 0;
  37. }
  38.  
  39.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161