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