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