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 w;
  11. w = *a;
  12. *a = *b;
  13. *b = w;
  14. }
  15.  
  16. int main(void) {
  17. int i,j;
  18.  
  19. Body a[5]={{1,65,169},{2,73,170},{3,59,161},{4,79,175},{5,55,168}};
  20.  
  21. for(i=0;i<4;i++){
  22. for(j=i+1;j<5;j++){
  23. if (a[i].height < a[j].height) {
  24. swap(&a[i], &a[j]);
  25. }
  26. }
  27. }
  28.  
  29. for (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.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
4, 79, 175
2, 73, 170
1, 65, 169
5, 55, 168
3, 59, 161