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