fork download
  1. #include <stdio.h>
  2.  
  3. typedef struct body {
  4. int id;
  5. int weight;
  6. int height;
  7. } Body;
  8.  
  9. void swap(Body *a, Body *b){
  10. Body tmp;
  11.  
  12. tmp = *a;
  13. *a = *b;
  14. *b = tmp;
  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 j=0; j<4; j++){
  27. for(int i=0; i<4-j; i++){
  28. if(data[i].height<data[i+1].height){
  29. swap(&data[i],&data[i+1]);
  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. }
  40.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161