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