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