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] = { {1, 65, 169},{2, 73, 170},{3, 59, 161},{4, 79, 175},{5, 55, 168} };
  17.  
  18. int i, j;
  19. for (i = 0; i < 4; i++) {
  20. for (j = i + 1; j < 5; j++) {
  21. if (data[i].height < data[j].height) {
  22. swap(&data[i], &data[j]);
  23. }
  24. }
  25. }
  26.  
  27. for (i = 0; i < 5; i++) {
  28. printf("%d, %d, %d\n",
  29. data[i].id,
  30. data[i].weight,
  31. data[i].height);
  32. }
  33.  
  34. return 0;
  35. }
  36.  
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