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