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. int n = sizeof(data)/sizeof(data[0]);
  15.  
  16. for(int i=0;i<n-1;i++){
  17. for(int j=0;j<n-i-1;j++){
  18. if(data[j].height<data[j+1].height){
  19. swap(&data[j],&data[j+1]);
  20. }
  21. }
  22. }
  23.  
  24. for(int i=0;i<5;i++){
  25. printf("%d.%d.%d\n",data[i].ID,data[i].weight,data[i].height);
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31. void swap(Body *i,Body *j){
  32.  
  33. Body a = *i;
  34. *i = *j;
  35. *j = a;
  36. }
  37.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
4.79.175
2.73.170
1.65.169
5.55.168
3.59.161