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

stdout
4,79,175
2,73,170
1,65,169
5,55,168
3,59,161