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