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