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