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