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