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