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