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 *i,Body *j);
  10.  
  11. int main(void) {
  12. Body a[] = {{1,65,169},{2,73,170},{3,59,161},{4,79,175},{5,55,168}};
  13.  
  14. int n = sizeof(a)/sizeof(a[0]);
  15.  
  16. for(int i=0;i<n-1;i++){
  17. for(int j=0;j<n-i-1;j++){
  18. if(a[j].height<a[j+1].height){
  19. swap(&a[j],&a[j+1]);
  20. }
  21. }
  22. }
  23.  
  24. for(int i=0;i<5;i++){
  25. printf("%d.%d.%d\n",a[i].ID,a[i].weight,a[i].height);
  26. }
  27.  
  28. return 0;
  29. }
  30.  
  31. void swap(Body *i,Body *j){
  32.  
  33. Body a = *i;
  34. *i = *j;
  35. *j = a;
  36. }
  37.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
4.79.175
2.73.170
1.65.169
5.55.168
3.59.161