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