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