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