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