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