fork download
  1. #include <stdio.h>
  2.  
  3. struct Body{
  4. int id;
  5. int weight;
  6. int height;
  7. }Body;
  8.  
  9. int swap(struct Body *x, struct Body *y){
  10. struct Body temp=*y;
  11. *y=*x;
  12. *x=temp;
  13. }
  14.  
  15. int main(void){
  16.  
  17. struct Body A[]={
  18. {1, 65, 169},
  19. {2, 73, 170},
  20. {3, 59, 161},
  21. {4, 79, 175},
  22. {5, 55, 168}};
  23.  
  24. int size=sizeof(A)/sizeof(A[0]);
  25.  
  26. for(int i=0; i<size-1; i++){
  27. for(int j=i+1; j<size; j++){
  28. if(A[i].height < A[j].height){
  29. swap(&A[i], &A[j]);}
  30. }
  31. }
  32. for(int k=0; k<size; k++){
  33. printf("%d : %d : %d\n",A[k].id, A[k].weight, A[k].height);
  34.  
  35. }
  36.  
  37. return 0;
  38. }
  39.  
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