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