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