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