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