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.  
  11. int main(void)
  12. {
  13. Body la[] = {
  14. {1, 65, 169},
  15. {2, 73, 170},
  16. {3, 59, 161},
  17. {4, 79, 175},
  18. {5, 55, 168}
  19. };
  20. int n = sizeof(la) / sizeof(la[0]);
  21.  
  22. for(int i=0; i < n - 1; i++){
  23. for(int j=0; j < n - 1 - i; j++){
  24. if(la[j].height < la[j+1].height){
  25. swap(&la[j], &la[j+1]);
  26. }
  27. }
  28. }
  29. for(int i = 0; i < n; i++){
  30. printf("%d, %d, %d\n", la[i].id, la[i].weight, la[i].height);
  31. }
  32. return 0;
  33. }
  34. void swap(Body *a, Body*b){
  35. Body temp = *a;
  36. *a = *b;
  37. *b = temp;
  38.  
  39. }
  40.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161