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