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