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