fork(1) 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 body[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(body[i].height < body[j].height){
  22. swap(&body[i],&body[j]);
  23. }
  24. }
  25. }
  26. for(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. }
  31.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
4,79,175
2,73,170
1,65,169
5,55,168
3,59,161