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