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