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