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