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