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