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