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