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