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