fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. typedef struct {
  5. int id;
  6. int weight;
  7. int height;
  8. } Body;
  9.  
  10. void swap(Body *a, Body *b) {
  11. int w;
  12.  
  13. w = a->id;
  14. a->id = b->id;
  15. b->id = w;
  16.  
  17. w = a->weight;
  18. a->weight = b->weight;
  19. b->weight = w;
  20.  
  21. w = a->height;
  22. a->height = b->height;
  23. b->height = w;
  24. }
  25.  
  26. int main() {
  27. Body a[] = {
  28. {1, 65, 169},
  29. {2, 73, 170},
  30. {3, 59, 161},
  31. {4, 79, 175},
  32. {5, 55, 168}
  33. };
  34.  
  35.  
  36.  
  37. for (int i = 0; i < 4; i++) {
  38. for (int j = 0; j < 4-i; j++) {
  39. if (a[j].height < a[j + 1].height) {
  40. swap(&a[j], &a[j + 1]);
  41. }
  42. }
  43. }
  44.  
  45. for (int i = 0; i < 5; i++) {
  46. printf("%d, %d, %d\n", a[i].id, a[i].weight, a[i].height);
  47. }
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161