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