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*a,Body*b ){
  9. Body temp=*a;
  10. *a=*b;
  11. *b=temp;
  12. }
  13.  
  14. int main(void) {
  15. Body body[5]={{1,65,169},{2,73,170},{3,59,161},{4,79,175},{5,55,168}};
  16. int i;
  17. int j;
  18. for( i=0;i<5;i++){
  19. for(j=i+1;j<5;j++){
  20. if(body[i].height<body[j].height){
  21. swap(&body[i],&body[j]);
  22. }
  23. }
  24. }
  25. for(i=0;i<5;i++)
  26. printf("%d,%d,%d\n",body[i].id,body[i].weight,body[i].height);
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
4,79,175
2,73,170
1,65,169
5,55,168
3,59,161